llvm.org GIT mirror llvm / 2ef8a59
[AArch64] Spot SBFX-compatible code expressed with sign_extend. This is very similar to r271677, but for extracts from i32 with the SIGN_EXTEND acting on a arithmetic shift. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@271717 91177308-0d34-0410-b5e6-96231b3b80d8 Chad Rosier 4 years ago
2 changed file(s) with 40 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
163163 void SelectPostStoreLane(SDNode *N, unsigned NumVecs, unsigned Opc);
164164
165165 bool tryBitfieldExtractOp(SDNode *N);
166 bool tryBitfieldExtractOpFromSExt(SDNode *N);
166167 bool tryBitfieldInsertOp(SDNode *N);
167168 bool tryBitfieldInsertInZeroOp(SDNode *N);
168169
16491650 return true;
16501651 }
16511652
1653 bool AArch64DAGToDAGISel::tryBitfieldExtractOpFromSExt(SDNode *N) {
1654 assert(N->getOpcode() == ISD::SIGN_EXTEND);
1655
1656 EVT VT = N->getValueType(0);
1657 EVT NarrowVT = N->getOperand(0)->getValueType(0);
1658 if (VT != MVT::i64 || NarrowVT != MVT::i32)
1659 return false;
1660
1661 uint64_t ShiftImm;
1662 SDValue Op = N->getOperand(0);
1663 if (!isOpcWithIntImmediate(Op.getNode(), ISD::SRA, ShiftImm))
1664 return false;
1665
1666 SDLoc dl(N);
1667 // Extend the incoming operand of the shift to 64-bits.
1668 SDValue Opd0 = Widen(CurDAG, Op.getOperand(0));
1669 unsigned Immr = ShiftImm;
1670 unsigned Imms = NarrowVT.getSizeInBits() - 1;
1671 SDValue Ops[] = {Opd0, CurDAG->getTargetConstant(Immr, dl, VT),
1672 CurDAG->getTargetConstant(Imms, dl, VT)};
1673 CurDAG->SelectNodeTo(N, AArch64::SBFMXri, VT, Ops);
1674 return true;
1675 }
1676
16521677 static bool isBitfieldExtractOp(SelectionDAG *CurDAG, SDNode *N, unsigned &Opc,
16531678 SDValue &Opd0, unsigned &Immr, unsigned &Imms,
16541679 unsigned NumberOfIgnoredLowBits = 0,
25842609 if (tryBitfieldExtractOp(Node))
25852610 return;
25862611 if (tryBitfieldInsertInZeroOp(Node))
2612 return;
2613 break;
2614
2615 case ISD::SIGN_EXTEND:
2616 if (tryBitfieldExtractOpFromSExt(Node))
25872617 return;
25882618 break;
25892619
0 ; RUN: llc -mtriple=aarch64-none-linux-gnu < %s | FileCheck %s
1
2 ; CHECK-LABEL: @test1
3 ; CHECK: sbfx {{x[0-9]+}}, x0, #23, #9
4 define i64 @test1(i32 %a) {
5 %tmp = ashr i32 %a, 23
6 %ext = sext i32 %tmp to i64
7 %res = add i64 %ext, 1
8 ret i64 %res
9 }