Skip to content

Commit 6fbc606

Browse files
committed
[Xtensa] Implement lowering llvm intrinsics fshr/fshl.
1 parent 22378fe commit 6fbc606

File tree

3 files changed

+47
-0
lines changed

3 files changed

+47
-0
lines changed

llvm/lib/Target/Xtensa/XtensaISelLowering.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,10 @@ XtensaTargetLowering::XtensaTargetLowering(const TargetMachine &tm,
188188
setOperationAction(ISD::SRA_PARTS, MVT::i32, Custom);
189189
setOperationAction(ISD::SRL_PARTS, MVT::i32, Custom);
190190

191+
// Funnel shifts
192+
setOperationAction(ISD::FSHR, MVT::i32, Custom);
193+
setOperationAction(ISD::FSHL, MVT::i32, Custom);
194+
191195
// Bit Manipulation
192196
setOperationAction(ISD::BSWAP, MVT::i32, Expand);
193197
setOperationAction(ISD::BSWAP, MVT::i64, Expand);
@@ -1674,6 +1678,23 @@ SDValue XtensaTargetLowering::LowerShiftRightParts(SDValue Op,
16741678
return DAG.getMergeValues(Ops, DL);
16751679
}
16761680

1681+
SDValue XtensaTargetLowering::LowerFunnelShift(SDValue Op,
1682+
SelectionDAG &DAG) const {
1683+
SDLoc DL(Op);
1684+
SDValue Op0 = Op.getOperand(0);
1685+
SDValue Op1 = Op.getOperand(1);
1686+
SDValue Shamt = Op.getOperand(2);
1687+
MVT VT = Op.getSimpleValueType();
1688+
1689+
bool IsFSHR = Op.getOpcode() == ISD::FSHR;
1690+
assert((VT == MVT::i32) && "Unexpected funnel shift type!");
1691+
1692+
SDValue SetSAR = DAG.getNode(IsFSHR ? XtensaISD::SSR : XtensaISD::SSL, DL,
1693+
MVT::Glue, Shamt);
1694+
return DAG.getNode(XtensaISD::SRC, DL, VT, IsFSHR ? Op0 : Op1,
1695+
IsFSHR ? Op1 : Op0, SetSAR);
1696+
}
1697+
16771698
SDValue XtensaTargetLowering::LowerATOMIC_FENCE(SDValue Op,
16781699
SelectionDAG &DAG) const {
16791700
SDLoc DL(Op);
@@ -1728,6 +1749,9 @@ SDValue XtensaTargetLowering::LowerOperation(SDValue Op,
17281749
return LowerShiftRightParts(Op, DAG, true);
17291750
case ISD::SRL_PARTS:
17301751
return LowerShiftRightParts(Op, DAG, false);
1752+
case ISD::FSHL:
1753+
case ISD::FSHR:
1754+
return LowerFunnelShift(Op, DAG);
17311755
default:
17321756
llvm_unreachable("Unexpected node to lower");
17331757
}

llvm/lib/Target/Xtensa/XtensaISelLowering.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ class XtensaTargetLowering : public TargetLowering {
195195

196196
SDValue LowerShiftLeftParts(SDValue Op, SelectionDAG &DAG) const;
197197
SDValue LowerShiftRightParts(SDValue Op, SelectionDAG &DAG, bool IsSRA) const;
198+
SDValue LowerFunnelShift(SDValue Op, SelectionDAG &DAG) const;
198199

199200
SDValue LowerATOMIC_FENCE(SDValue Op, SelectionDAG &DAG) const;
200201

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
; RUN: llc -O1 -mtriple=xtensa -mcpu=esp32 %s -o - | FileCheck %s
2+
3+
define dso_local i32 @test_fshr(i32 %value, i32 %shift) nounwind {
4+
; CHECK-LABEL: @test_fshr
5+
; CHECK: ssr a3
6+
; CHECK: src a2, a2, a2
7+
entry:
8+
%0 = tail call i32 @llvm.fshr.i32(i32 %value, i32 %value, i32 %shift)
9+
ret i32 %0
10+
}
11+
12+
define dso_local i32 @test_fshl(i32 %value, i32 %shift) nounwind {
13+
; CHECK-LABEL: @test_fshl
14+
; CHECK: ssl a3
15+
; CHECK: src a2, a2, a2
16+
entry:
17+
%0 = tail call i32 @llvm.fshl.i32(i32 %value, i32 %value, i32 %shift)
18+
ret i32 %0
19+
}
20+
21+
declare i32 @llvm.fshr.i32(i32, i32, i32) nounwind
22+
declare i32 @llvm.fshl.i32(i32, i32, i32) nounwind

0 commit comments

Comments
 (0)