Skip to content

Commit a59976b

Browse files
authored
[InstCombine] Drop noundef attributes in foldCttzCtlz (#116718)
Closes #112068.
1 parent b24acc0 commit a59976b

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -505,8 +505,10 @@ static Instruction *foldCttzCtlz(IntrinsicInst &II, InstCombinerImpl &IC) {
505505

506506
// If ctlz/cttz is only used as a shift amount, set is_zero_poison to true.
507507
if (II.hasOneUse() && match(Op1, m_Zero()) &&
508-
match(II.user_back(), m_Shift(m_Value(), m_Specific(&II))))
508+
match(II.user_back(), m_Shift(m_Value(), m_Specific(&II)))) {
509+
II.dropUBImplyingAttrsAndMetadata();
509510
return IC.replaceOperand(II, 1, IC.Builder.getTrue());
511+
}
510512

511513
Constant *C;
512514

llvm/test/Transforms/InstCombine/shift-cttz-ctlz.ll

+16
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,22 @@ entry:
1515
ret i32 %res
1616
}
1717

18+
; Make sure that noundef is dropped.
19+
20+
define i32 @shl_cttz_false_noundef(i32 %x, i32 %y) {
21+
; CHECK-LABEL: define i32 @shl_cttz_false_noundef(
22+
; CHECK-SAME: i32 [[X:%.*]], i32 [[Y:%.*]]) {
23+
; CHECK-NEXT: entry:
24+
; CHECK-NEXT: [[CTTZ:%.*]] = call range(i32 0, 33) i32 @llvm.cttz.i32(i32 [[Y]], i1 true)
25+
; CHECK-NEXT: [[RES:%.*]] = shl i32 [[X]], [[CTTZ]]
26+
; CHECK-NEXT: ret i32 [[RES]]
27+
;
28+
entry:
29+
%cttz = call noundef i32 @llvm.cttz.i32(i32 %y, i1 false)
30+
%res = shl i32 %x, %cttz
31+
ret i32 %res
32+
}
33+
1834
define i32 @shl_ctlz_false(i32 %x, i32 %y) {
1935
; CHECK-LABEL: define i32 @shl_ctlz_false(
2036
; CHECK-SAME: i32 [[X:%.*]], i32 [[Y:%.*]]) {

0 commit comments

Comments
 (0)