[llvm] r307179 - [DAGCombiner] visitRotate patch to optimize pair of ROTR/ROTL instructions into one with combined shift operand.
Andrew Zhogin via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 5 10:55:43 PDT 2017
Author: andrew.zhogin
Date: Wed Jul 5 10:55:42 2017
New Revision: 307179
URL: http://llvm.org/viewvc/llvm-project?rev=307179&view=rev
Log:
[DAGCombiner] visitRotate patch to optimize pair of ROTR/ROTL instructions into one with combined shift operand.
For two ROTR operations with shifts C1, C2; combined shift operand will be (C1 + C2) % bitsize.
Differential revision: https://reviews.llvm.org/D12833
Modified:
llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
llvm/trunk/test/CodeGen/ARM/ror.ll
llvm/trunk/test/CodeGen/X86/combine-rotates.ll
Modified: llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp?rev=307179&r1=307178&r2=307179&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp (original)
+++ llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp Wed Jul 5 10:55:42 2017
@@ -5279,6 +5279,25 @@ SDValue DAGCombiner::visitRotate(SDNode
if (SDValue NewOp1 = distributeTruncateThroughAnd(N1.getNode()))
return DAG.getNode(N->getOpcode(), dl, VT, N0, NewOp1);
}
+
+ unsigned NextOp = N0.getOpcode();
+ // fold (rot* (rot* x, c2), c1) -> (rot* x, c1 +- c2 % bitsize)
+ if (NextOp == ISD::ROTL || NextOp == ISD::ROTR)
+ if (SDNode *C1 = DAG.isConstantIntBuildVectorOrConstantInt(N1))
+ if (SDNode *C2 =
+ DAG.isConstantIntBuildVectorOrConstantInt(N0.getOperand(1))) {
+ bool SameSide = (N->getOpcode() == NextOp);
+ unsigned CombineOp = SameSide ? ISD::ADD : ISD::SUB;
+ if (SDValue CombinedShift =
+ DAG.FoldConstantArithmetic(CombineOp, dl, VT, C1, C2)) {
+ unsigned Bitsize = VT.getScalarSizeInBits();
+ SDValue BitsizeC = DAG.getConstant(Bitsize, dl, VT);
+ SDValue CombinedShiftNorm = DAG.FoldConstantArithmetic(
+ ISD::SREM, dl, VT, CombinedShift.getNode(), BitsizeC.getNode());
+ return DAG.getNode(
+ N->getOpcode(), dl, VT, N0->getOperand(0), CombinedShiftNorm);
+ }
+ }
return SDValue();
}
Modified: llvm/trunk/test/CodeGen/ARM/ror.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/ARM/ror.ll?rev=307179&r1=307178&r2=307179&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/ARM/ror.ll (original)
+++ llvm/trunk/test/CodeGen/ARM/ror.ll Wed Jul 5 10:55:42 2017
@@ -3,8 +3,7 @@
; rotr (rotr x, 4), 6 -> rotr x, 10 -> ror r0, r0, #10
define i32 @test1(i32 %x) nounwind readnone {
; CHECK-LABEL: test1:
-; CHECK: ror r0, r0, #4
-; CHECK: ror r0, r0, #6
+; CHECK: ror r0, r0, #10
; CHECK: bx lr
entry:
%high_part.i = shl i32 %x, 28
@@ -19,10 +18,8 @@ entry:
; the same vector test
define <2 x i32> @test2(<2 x i32> %x) nounwind readnone {
; CHECK-LABEL: test2:
-; CHECK: ror r0, r0, #4
-; CHECK: ror r1, r1, #4
-; CHECK: ror r0, r0, #6
-; CHECK: ror r1, r1, #6
+; CHECK: ror r0, r0, #10
+; CHECK: ror r1, r1, #10
; CHECK: bx lr
entry:
%high_part.i = shl <2 x i32> %x, <i32 28, i32 28>
Modified: llvm/trunk/test/CodeGen/X86/combine-rotates.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/combine-rotates.ll?rev=307179&r1=307178&r2=307179&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/X86/combine-rotates.ll (original)
+++ llvm/trunk/test/CodeGen/X86/combine-rotates.ll Wed Jul 5 10:55:42 2017
@@ -35,8 +35,7 @@ define <4 x i32> @combine_vec_rot_rot(<4
define <4 x i32> @combine_vec_rot_rot_splat(<4 x i32> %x) {
; XOP-LABEL: combine_vec_rot_rot_splat:
; XOP: # BB#0:
-; XOP-NEXT: vprotd $29, %xmm0, %xmm0
-; XOP-NEXT: vprotd $10, %xmm0, %xmm0
+; XOP-NEXT: vprotd $7, %xmm0, %xmm0
; XOP-NEXT: retq
;
; AVX512-LABEL: combine_vec_rot_rot_splat:
@@ -60,8 +59,7 @@ define <4 x i32> @combine_vec_rot_rot_sp
define <4 x i32> @combine_vec_rot_rot_splat_zero(<4 x i32> %x) {
; XOP-LABEL: combine_vec_rot_rot_splat_zero:
; XOP: # BB#0:
-; XOP-NEXT: vprotd $31, %xmm0, %xmm0
-; XOP-NEXT: vprotd $1, %xmm0, %xmm0
+; XOP-NEXT: vprotd $0, %xmm0, %xmm0
; XOP-NEXT: retq
;
; AVX512-LABEL: combine_vec_rot_rot_splat_zero:
More information about the llvm-commits
mailing list