Skip to content

Commit d6a319b

Browse files
committed
support of vectors
1 parent e2896c8 commit d6a319b

File tree

2 files changed

+23
-18
lines changed

2 files changed

+23
-18
lines changed

llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10972,7 +10972,8 @@ SDValue DAGCombiner::visitSRL(SDNode *N) {
1097210972
return DAG.getNode(ISD::SRL, DL, VT, N0, NewOp1);
1097310973
}
1097410974

10975-
// fold (srl (or x, (shl (zext y), c1)), c1) -> (or (srl x, c1), (zext y))
10975+
// fold (srl (logic_op x, (shl (zext y), c1)), c1)
10976+
// -> (logic_op (srl x, c1), (zext y))
1097610977
// c1 <= leadingzeros(zext(y))
1097710978
if (N1C && ISD::isBitwiseLogicOp(N0.getOpcode())) {
1097810979
SDValue lhs = N0.getOperand(0);
@@ -10995,7 +10996,7 @@ SDValue DAGCombiner::visitSRL(SDNode *N) {
1099510996
if (N1C->getZExtValue() <= numLeadingZeros) {
1099610997
return DAG.getNode(
1099710998
N0.getOpcode(), SDLoc(N0), VT,
10998-
DAG.getNode(ISD::SRL, SDLoc(N0), VT, other, SDValue(N1C, 0)),
10999+
DAG.getNode(ISD::SRL, SDLoc(N0), VT, other, N1),
1099911000
zext);
1100011001
}
1100111002
}

llvm/test/CodeGen/NVPTX/shift-opt.ll

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -57,33 +57,37 @@ define i64 @test_and(i64 %x, i32 %y) {
5757
ret i64 %srl
5858
}
5959

60-
define <2 x i64> @test_or_vec(<2 x i64> %x, <2 x i32> %y) {
60+
define <2 x i16> @test_vec(<2 x i16> %x, <2 x i8> %y) {
6161
;
6262
; srl (or (x, shl(zext(y),c1)),c1) -> or(srl(x,c1), zext(y))
6363
; c1 <= leadingzeros(zext(y))
6464
;
65-
; CHECK-LABEL: test_or
66-
; CHECK: ld.param.u64 %[[X:rd[0-9]+]], [test_or_param_0];
67-
; CHECK: ld.param.u32 %[[Y:rd[0-9]+]], [test_or_param_1];
68-
; CHECK: shr.u64 %[[SHR:rd[0-9]+]], %[[X]], 5;
69-
; CHECK: or.b64 %[[LOP:rd[0-9]+]], %[[SHR]], %[[Y]];
70-
; CHECK: st.param.b64 [func_retval0], %[[LOP]];
65+
; CHECK-LABEL: test_vec
66+
; CHECK: ld.param.u32 %[[X:r[0-9]+]], [test_vec_param_0];
67+
; CHECK: ld.param.u32 %[[P1:r[0-9]+]], [test_vec_param_1];
68+
; CHECK: and.b32 %[[Y:r[0-9]+]], %[[P1]], 16711935;
69+
; CHECK: mov.b32 {%[[X1:rs[0-9]+]], %[[X2:rs[0-9]+]]}, %[[X]];
70+
; CHECK: shr.u16 %[[SHR2:rs[0-9]+]], %[[X2]], 5;
71+
; CHECK: shr.u16 %[[SHR1:rs[0-9]+]], %[[X1]], 5;
72+
; CHECK: mov.b32 %[[SHR:r[0-9]+]], {%[[SHR1]], %[[SHR2]]};
73+
; CHECK: or.b32 %[[LOP:r[0-9]+]], %[[SHR]], %[[Y]];
74+
; CHECK: st.param.b32 [func_retval0], %[[LOP]];
7175
;
72-
%ext = zext <2 x i32> %y to <2 x i64>
73-
%shl = shl <2 x i64> %ext, splat(i64 5)
74-
%or = or <2 x i64> %x, %shl
75-
%srl = lshr <2 x i64> %or, splat(i64 5)
76-
ret <2 x i64> %srl
76+
%ext = zext <2 x i8> %y to <2 x i16>
77+
%shl = shl <2 x i16> %ext, splat(i16 5)
78+
%or = or <2 x i16> %x, %shl
79+
%srl = lshr <2 x i16> %or, splat(i16 5)
80+
ret <2 x i16> %srl
7781
}
7882

79-
define i64 @test2(i64 %x, i32 %y) {
83+
define i64 @test_negative_c(i64 %x, i32 %y) {
8084
;
8185
; srl (or (x, shl(zext(y),c1)),c1) -> or(srl(x,c1), zext(y))
8286
; c1 > leadingzeros(zext(y)).
8387
;
84-
; CHECK-LABEL: test2
85-
; CHECK: ld.param.u64 %[[X:rd[0-9]+]], [test2_param_0];
86-
; CHECK: ld.param.u32 %[[Y:rd[0-9]+]], [test2_param_1];
88+
; CHECK-LABEL: test_negative_c
89+
; CHECK: ld.param.u64 %[[X:rd[0-9]+]], [test_negative_c_param_0];
90+
; CHECK: ld.param.u32 %[[Y:rd[0-9]+]], [test_negative_c_param_1];
8791
; CHECK: shl.b64 %[[SHL:rd[0-9]+]], %[[Y]], 33;
8892
; CHECK: or.b64 %[[OR:rd[0-9]+]], %[[X]], %[[SHL]];
8993
; CHECK: shr.u64 %[[SHR:rd[0-9]+]], %[[OR]], 33;

0 commit comments

Comments
 (0)