[llvm] r271717 - [AArch64] Spot SBFX-compatible code expressed with sign_extend.
Chad Rosier via llvm-commits
llvm-commits at lists.llvm.org
Fri Jun 3 13:05:49 PDT 2016
Author: mcrosier
Date: Fri Jun 3 15:05:49 2016
New Revision: 271717
URL: http://llvm.org/viewvc/llvm-project?rev=271717&view=rev
Log:
[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.
Added:
llvm/trunk/test/CodeGen/AArch64/bitfield-extract.ll
Modified:
llvm/trunk/lib/Target/AArch64/AArch64ISelDAGToDAG.cpp
Modified: llvm/trunk/lib/Target/AArch64/AArch64ISelDAGToDAG.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/AArch64/AArch64ISelDAGToDAG.cpp?rev=271717&r1=271716&r2=271717&view=diff
==============================================================================
--- llvm/trunk/lib/Target/AArch64/AArch64ISelDAGToDAG.cpp (original)
+++ llvm/trunk/lib/Target/AArch64/AArch64ISelDAGToDAG.cpp Fri Jun 3 15:05:49 2016
@@ -164,6 +164,7 @@ public:
void SelectPostStoreLane(SDNode *N, unsigned NumVecs, unsigned Opc);
bool tryBitfieldExtractOp(SDNode *N);
+ bool tryBitfieldExtractOpFromSExt(SDNode *N);
bool tryBitfieldInsertOp(SDNode *N);
bool tryBitfieldInsertInZeroOp(SDNode *N);
@@ -1650,6 +1651,30 @@ static bool isBitfieldExtractOpFromShr(S
return true;
}
+bool AArch64DAGToDAGISel::tryBitfieldExtractOpFromSExt(SDNode *N) {
+ assert(N->getOpcode() == ISD::SIGN_EXTEND);
+
+ EVT VT = N->getValueType(0);
+ EVT NarrowVT = N->getOperand(0)->getValueType(0);
+ if (VT != MVT::i64 || NarrowVT != MVT::i32)
+ return false;
+
+ uint64_t ShiftImm;
+ SDValue Op = N->getOperand(0);
+ if (!isOpcWithIntImmediate(Op.getNode(), ISD::SRA, ShiftImm))
+ return false;
+
+ SDLoc dl(N);
+ // Extend the incoming operand of the shift to 64-bits.
+ SDValue Opd0 = Widen(CurDAG, Op.getOperand(0));
+ unsigned Immr = ShiftImm;
+ unsigned Imms = NarrowVT.getSizeInBits() - 1;
+ SDValue Ops[] = {Opd0, CurDAG->getTargetConstant(Immr, dl, VT),
+ CurDAG->getTargetConstant(Imms, dl, VT)};
+ CurDAG->SelectNodeTo(N, AArch64::SBFMXri, VT, Ops);
+ return true;
+}
+
static bool isBitfieldExtractOp(SelectionDAG *CurDAG, SDNode *N, unsigned &Opc,
SDValue &Opd0, unsigned &Immr, unsigned &Imms,
unsigned NumberOfIgnoredLowBits = 0,
@@ -2588,6 +2613,11 @@ void AArch64DAGToDAGISel::Select(SDNode
return;
break;
+ case ISD::SIGN_EXTEND:
+ if (tryBitfieldExtractOpFromSExt(Node))
+ return;
+ break;
+
case ISD::OR:
if (tryBitfieldInsertOp(Node))
return;
Added: llvm/trunk/test/CodeGen/AArch64/bitfield-extract.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/AArch64/bitfield-extract.ll?rev=271717&view=auto
==============================================================================
--- llvm/trunk/test/CodeGen/AArch64/bitfield-extract.ll (added)
+++ llvm/trunk/test/CodeGen/AArch64/bitfield-extract.ll Fri Jun 3 15:05:49 2016
@@ -0,0 +1,10 @@
+; RUN: llc -mtriple=aarch64-none-linux-gnu < %s | FileCheck %s
+
+; CHECK-LABEL: @test1
+; CHECK: sbfx {{x[0-9]+}}, x0, #23, #9
+define i64 @test1(i32 %a) {
+ %tmp = ashr i32 %a, 23
+ %ext = sext i32 %tmp to i64
+ %res = add i64 %ext, 1
+ ret i64 %res
+}
More information about the llvm-commits
mailing list