Skip to content

Commit 3b31baf

Browse files
committed
negative tests. Multiple usage
Signed-off-by: Alexander Peskov <[email protected]>
1 parent 71db1d9 commit 3b31baf

File tree

2 files changed

+37
-9
lines changed

2 files changed

+37
-9
lines changed

llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10975,7 +10975,7 @@ SDValue DAGCombiner::visitSRL(SDNode *N) {
1097510975
// fold (srl (logic_op x, (shl (zext y), c1)), c1)
1097610976
// -> (logic_op (srl x, c1), (zext y))
1097710977
// c1 <= leadingzeros(zext(y))
10978-
if (N1C && ISD::isBitwiseLogicOp(N0.getOpcode())) {
10978+
if (N1C && ISD::isBitwiseLogicOp(N0.getOpcode()) && N0.hasOneUse()) {
1097910979
SDValue lhs = N0.getOperand(0);
1098010980
SDValue rhs = N0.getOperand(1);
1098110981
SDValue shl;
@@ -10987,7 +10987,7 @@ SDValue DAGCombiner::visitSRL(SDNode *N) {
1098710987
shl = rhs;
1098810988
other = lhs;
1098910989
}
10990-
if (shl && shl.getOperand(1) == N1) {
10990+
if (shl && shl.getOperand(1) == N1 && shl.hasOneUse()) {
1099110991
SDValue zext = shl.getOperand(0);
1099210992
if (zext.getOpcode() == ISD::ZERO_EXTEND) {
1099310993
unsigned numLeadingZeros =

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

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -107,15 +107,17 @@ define i64 @test_negative_use_lop(i64 %x, i32 %y) {
107107
;
108108
; srl (or (x, shl(zext(y),c1)),c1) -> or(srl(x,c1), zext(y))
109109
; c1 <= leadingzeros(zext(y))
110-
;
111-
;
110+
; multiple usage of "or"
112111
;
113112
; CHECK-LABEL: test_negative_use_lop
114-
; CHECK: ld.param.u64 %[[X:rd[0-9]+]], [test_negative_c_param_0];
115-
; CHECK: ld.param.u32 %[[Y:rd[0-9]+]], [test_negative_c_param_1];
116-
; CHECK: shl.b64 %[[SHL:rd[0-9]+]], %[[Y]], 33;
113+
; CHECK: ld.param.u64 %[[X:rd[0-9]+]], [test_negative_use_lop_param_0];
114+
; CHECK: ld.param.u32 %[[Y:r[0-9]+]], [test_negative_use_lop_param_1];
115+
; CHECK: mul.wide.u32 %[[SHL:rd[0-9]+]], %[[Y]], 32;
117116
; CHECK: or.b64 %[[OR:rd[0-9]+]], %[[X]], %[[SHL]];
118-
; CHECK: shr.u64 %[[SHR:rd[0-9]+]], %[[OR]], 33;
117+
; CHECK: shr.u64 %[[SHR:rd[0-9]+]], %[[OR]], 5;
118+
; CHECK: { // callseq
119+
; CHECK: st.param.b64 [param0], %[[OR]];
120+
; CHECK: } // callseq
119121
; CHECK: st.param.b64 [func_retval0], %[[SHR]];
120122
;
121123
%ext = zext i32 %y to i64
@@ -124,4 +126,30 @@ define i64 @test_negative_use_lop(i64 %x, i32 %y) {
124126
%srl = lshr i64 %or, 5
125127
call void @use(i64 %or)
126128
ret i64 %srl
127-
}
129+
}
130+
131+
132+
define i64 @test_negative_use_shl(i64 %x, i32 %y) {
133+
;
134+
; srl (or (x, shl(zext(y),c1)),c1) -> or(srl(x,c1), zext(y))
135+
; c1 <= leadingzeros(zext(y))
136+
; multiple usage of "shl"
137+
;
138+
; CHECK-LABEL: test_negative_use_shl
139+
; CHECK: ld.param.u64 %[[X:rd[0-9]+]], [test_negative_use_shl_param_0];
140+
; CHECK: ld.param.u32 %[[Y:r[0-9]+]], [test_negative_use_shl_param_1];
141+
; CHECK: mul.wide.u32 %[[SHL:rd[0-9]+]], %[[Y]], 32;
142+
; CHECK: or.b64 %[[OR:rd[0-9]+]], %[[X]], %[[SHL]];
143+
; CHECK: shr.u64 %[[SHR:rd[0-9]+]], %[[OR]], 5;
144+
; CHECK: { // callseq
145+
; CHECK: st.param.b64 [param0], %[[SHL]];
146+
; CHECK: } // callseq
147+
; CHECK: st.param.b64 [func_retval0], %[[SHR]];
148+
;
149+
%ext = zext i32 %y to i64
150+
%shl = shl i64 %ext, 5
151+
%or = or i64 %x, %shl
152+
%srl = lshr i64 %or, 5
153+
call void @use(i64 %shl)
154+
ret i64 %srl
155+
}

0 commit comments

Comments
 (0)