Skip to content

Commit 9bea770

Browse files
committed
[InstCombine] Only requite not-undef in select equiv fold
As the comment already indicates, only replacement with undef is problematic, as it introduces an additional use of undef. Use the correct ValueTracking helper.
1 parent 60429fb commit 9bea770

File tree

2 files changed

+3
-6
lines changed

2 files changed

+3
-6
lines changed

llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1294,8 +1294,7 @@ Instruction *InstCombinerImpl::foldSelectValueEquivalence(SelectInst &Sel,
12941294
// X == Y ? X : Z with X == Y ? Y : Z, as that would lead to an infinite
12951295
// replacement cycle.
12961296
Value *CmpLHS = Cmp.getOperand(0), *CmpRHS = Cmp.getOperand(1);
1297-
if (TrueVal != CmpLHS &&
1298-
isGuaranteedNotToBeUndefOrPoison(CmpRHS, SQ.AC, &Sel, &DT)) {
1297+
if (TrueVal != CmpLHS && isGuaranteedNotToBeUndef(CmpRHS, SQ.AC, &Sel, &DT)) {
12991298
if (Value *V = simplifyWithOpReplaced(TrueVal, CmpLHS, CmpRHS, SQ,
13001299
/* AllowRefinement */ true))
13011300
// Require either the replacement or the simplification result to be a
@@ -1316,8 +1315,7 @@ Instruction *InstCombinerImpl::foldSelectValueEquivalence(SelectInst &Sel,
13161315
if (replaceInInstruction(TrueVal, CmpLHS, CmpRHS))
13171316
return &Sel;
13181317
}
1319-
if (TrueVal != CmpRHS &&
1320-
isGuaranteedNotToBeUndefOrPoison(CmpLHS, SQ.AC, &Sel, &DT))
1318+
if (TrueVal != CmpRHS && isGuaranteedNotToBeUndef(CmpLHS, SQ.AC, &Sel, &DT))
13211319
if (Value *V = simplifyWithOpReplaced(TrueVal, CmpRHS, CmpLHS, SQ,
13221320
/* AllowRefinement */ true))
13231321
if (isa<Constant>(CmpLHS) || isa<Constant>(V))

llvm/test/Transforms/InstCombine/select.ll

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2852,8 +2852,7 @@ define i8 @select_replacement_sub_noundef_but_may_be_poison(i8 %x, i8 noundef %y
28522852
; CHECK-LABEL: @select_replacement_sub_noundef_but_may_be_poison(
28532853
; CHECK-NEXT: [[Y:%.*]] = shl nuw i8 [[YY:%.*]], 1
28542854
; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[Y]], [[X:%.*]]
2855-
; CHECK-NEXT: [[SUB:%.*]] = sub i8 [[X]], [[Y]]
2856-
; CHECK-NEXT: [[SEL:%.*]] = select i1 [[CMP]], i8 [[SUB]], i8 [[Z:%.*]]
2855+
; CHECK-NEXT: [[SEL:%.*]] = select i1 [[CMP]], i8 0, i8 [[Z:%.*]]
28572856
; CHECK-NEXT: ret i8 [[SEL]]
28582857
;
28592858
%y = shl nuw i8 %yy, 1

0 commit comments

Comments
 (0)