Skip to content

Commit 16e2ec8

Browse files
committed
[ValueTracking] Make undef element check more precise
If we're only checking for undef, then also only look for undef elements in the vector (rather than undef and poison).
1 parent 9bea770 commit 16e2ec8

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

llvm/lib/Analysis/ValueTracking.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7296,10 +7296,13 @@ static bool isGuaranteedNotToBeUndefOrPoison(
72967296
isa<ConstantPointerNull>(C) || isa<Function>(C))
72977297
return true;
72987298

7299-
if (C->getType()->isVectorTy() && !isa<ConstantExpr>(C))
7300-
return (!includesUndef(Kind) ? !C->containsPoisonElement()
7301-
: !C->containsUndefOrPoisonElement()) &&
7302-
!C->containsConstantExpression();
7299+
if (C->getType()->isVectorTy() && !isa<ConstantExpr>(C)) {
7300+
if (includesUndef(Kind) && C->containsUndefElement())
7301+
return false;
7302+
if (includesPoison(Kind) && C->containsPoisonElement())
7303+
return false;
7304+
return !C->containsConstantExpression();
7305+
}
73037306
}
73047307

73057308
// Strip cast operations from a pointer value.

llvm/test/Transforms/InstCombine/select.ll

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2787,8 +2787,7 @@ define <2 x i8> @select_replacement_add_eq_vec_nonuniform(<2 x i8> %x, <2 x i8>
27872787
define <2 x i8> @select_replacement_add_eq_vec_poison(<2 x i8> %x, <2 x i8> %y) {
27882788
; CHECK-LABEL: @select_replacement_add_eq_vec_poison(
27892789
; CHECK-NEXT: [[CMP:%.*]] = icmp eq <2 x i8> [[X:%.*]], <i8 1, i8 poison>
2790-
; CHECK-NEXT: [[ADD:%.*]] = add <2 x i8> [[X]], <i8 1, i8 1>
2791-
; CHECK-NEXT: [[SEL:%.*]] = select <2 x i1> [[CMP]], <2 x i8> [[ADD]], <2 x i8> [[Y:%.*]]
2790+
; CHECK-NEXT: [[SEL:%.*]] = select <2 x i1> [[CMP]], <2 x i8> <i8 2, i8 poison>, <2 x i8> [[Y:%.*]]
27922791
; CHECK-NEXT: ret <2 x i8> [[SEL]]
27932792
;
27942793
%cmp = icmp eq <2 x i8> %x, <i8 1, i8 poison>

0 commit comments

Comments
 (0)