Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -506,8 +506,10 @@ static Instruction *foldCttzCtlz(IntrinsicInst &II, InstCombinerImpl &IC) {

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

Constant *C;

Expand Down
16 changes: 16 additions & 0 deletions llvm/test/Transforms/InstCombine/shift-cttz-ctlz.ll
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,22 @@ entry:
ret i32 %res
}

; Make sure that noundef is dropped.

define i32 @shl_cttz_false_noundef(i32 %x, i32 %y) {
; CHECK-LABEL: define i32 @shl_cttz_false_noundef(
; CHECK-SAME: i32 [[X:%.*]], i32 [[Y:%.*]]) {
; CHECK-NEXT: entry:
; CHECK-NEXT: [[CTTZ:%.*]] = call range(i32 0, 33) i32 @llvm.cttz.i32(i32 [[Y]], i1 true)
; CHECK-NEXT: [[RES:%.*]] = shl i32 [[X]], [[CTTZ]]
; CHECK-NEXT: ret i32 [[RES]]
;
entry:
%cttz = call noundef i32 @llvm.cttz.i32(i32 %y, i1 false)
%res = shl i32 %x, %cttz
ret i32 %res
}

define i32 @shl_ctlz_false(i32 %x, i32 %y) {
; CHECK-LABEL: define i32 @shl_ctlz_false(
; CHECK-SAME: i32 [[X:%.*]], i32 [[Y:%.*]]) {
Expand Down