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
6 changes: 5 additions & 1 deletion llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1225,8 +1225,12 @@ static Value *foldSelectCttzCtlz(ICmpInst *ICI, Value *TrueVal, Value *FalseVal,
// zext/trunc) have one use (ending at the select), the cttz/ctlz result will
// not be used if the input is zero. Relax to 'zero is poison' for that case.
if (II->hasOneUse() && SelectArg->hasOneUse() &&
!match(II->getArgOperand(1), m_One()))
!match(II->getArgOperand(1), m_One())) {
II->setArgOperand(1, ConstantInt::getTrue(II->getContext()));
// noundef attribute on the intrinsic may no longer be valid.
II->dropUBImplyingAttrsAndMetadata();
IC.addToWorklist(II);
}

return nullptr;
}
Expand Down
13 changes: 13 additions & 0 deletions llvm/test/Transforms/InstCombine/select-cmp-cttz-ctlz.ll
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,19 @@ define i32 @test_cttz_not_bw(i32 %x) {
ret i32 %res
}

define i32 @test_cttz_not_bw_noundef(i32 %x) {
; CHECK-LABEL: @test_cttz_not_bw_noundef(
; CHECK-NEXT: [[CT:%.*]] = tail call range(i32 0, 33) i32 @llvm.cttz.i32(i32 [[X:%.*]], i1 true)
; CHECK-NEXT: [[CMP_NOT:%.*]] = icmp eq i32 [[X]], 0
; CHECK-NEXT: [[RES:%.*]] = select i1 [[CMP_NOT]], i32 123, i32 [[CT]]
; CHECK-NEXT: ret i32 [[RES]]
;
%ct = tail call noundef i32 @llvm.cttz.i32(i32 %x, i1 false)
%cmp = icmp ne i32 %x, 0
%res = select i1 %cmp, i32 %ct, i32 123
ret i32 %res
}

define i32 @test_cttz_not_bw_multiuse(i32 %x) {
; CHECK-LABEL: @test_cttz_not_bw_multiuse(
; CHECK-NEXT: [[CT:%.*]] = tail call range(i32 0, 33) i32 @llvm.cttz.i32(i32 [[X:%.*]], i1 false)
Expand Down
Loading