Skip to content

Commit 2e5c5eb

Browse files
committed
[InstCombine] Drop noundef in foldSelectCttzCtlz
1 parent 0e75af8 commit 2e5c5eb

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1225,8 +1225,12 @@ static Value *foldSelectCttzCtlz(ICmpInst *ICI, Value *TrueVal, Value *FalseVal,
12251225
// zext/trunc) have one use (ending at the select), the cttz/ctlz result will
12261226
// not be used if the input is zero. Relax to 'zero is poison' for that case.
12271227
if (II->hasOneUse() && SelectArg->hasOneUse() &&
1228-
!match(II->getArgOperand(1), m_One()))
1228+
!match(II->getArgOperand(1), m_One())) {
12291229
II->setArgOperand(1, ConstantInt::getTrue(II->getContext()));
1230+
// noundef attribute on the intrinsic may no longer be valid.
1231+
II->dropUBImplyingAttrsAndMetadata();
1232+
IC.addToWorklist(II);
1233+
}
12301234

12311235
return nullptr;
12321236
}

llvm/test/Transforms/InstCombine/select-cmp-cttz-ctlz.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ define i32 @test_cttz_not_bw(i32 %x) {
497497

498498
define i32 @test_cttz_not_bw_noundef(i32 %x) {
499499
; CHECK-LABEL: @test_cttz_not_bw_noundef(
500-
; CHECK-NEXT: [[CT:%.*]] = tail call noundef range(i32 0, 33) i32 @llvm.cttz.i32(i32 [[X:%.*]], i1 true)
500+
; CHECK-NEXT: [[CT:%.*]] = tail call range(i32 0, 33) i32 @llvm.cttz.i32(i32 [[X:%.*]], i1 true)
501501
; CHECK-NEXT: [[CMP_NOT:%.*]] = icmp eq i32 [[X]], 0
502502
; CHECK-NEXT: [[RES:%.*]] = select i1 [[CMP_NOT]], i32 123, i32 [[CT]]
503503
; CHECK-NEXT: ret i32 [[RES]]

0 commit comments

Comments
 (0)