Skip to content

Commit 3bf4d48

Browse files
committed
Fixing miscompilation due to undef picking the wrong branch
1 parent 3f61da5 commit 3bf4d48

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1735,17 +1735,15 @@ Value *InstCombinerImpl::SimplifyDemandedVectorElts(Value *V,
17351735
APInt DemandedLHS(DemandedElts), DemandedRHS(DemandedElts);
17361736
if (auto *CV = dyn_cast<ConstantVector>(Sel->getCondition())) {
17371737
for (unsigned i = 0; i < VWidth; i++) {
1738-
// isNullValue() always returns false when called on a ConstantExpr.
1739-
// Skip constant expressions to avoid propagating incorrect information.
17401738
Constant *CElt = CV->getAggregateElement(i);
1741-
if (isa<ConstantExpr>(CElt))
1742-
continue;
1739+
17431740
// TODO: If a select condition element is undef, we can demand from
17441741
// either side. If one side is known undef, choosing that side would
17451742
// propagate undef.
1743+
// isNullValue() always returns false when called on a ConstantExpr.
17461744
if (CElt->isNullValue())
17471745
DemandedLHS.clearBit(i);
1748-
else
1746+
else if (CElt->isOneValue())
17491747
DemandedRHS.clearBit(i);
17501748
}
17511749
}

llvm/test/Transforms/InstCombine/pr98435.ll

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
define <2 x i1> @pr98435(<2 x i1> %val) {
55
; CHECK-LABEL: define <2 x i1> @pr98435(
66
; CHECK-SAME: <2 x i1> [[VAL:%.*]]) {
7-
; CHECK-NEXT: ret <2 x i1> <i1 poison, i1 true>
7+
; CHECK-NEXT: [[VAL1:%.*]] = select <2 x i1> <i1 undef, i1 true>, <2 x i1> <i1 true, i1 true>, <2 x i1> [[VAL]]
8+
; CHECK-NEXT: ret <2 x i1> [[VAL1]]
89
;
910
%val1 = select <2 x i1> <i1 undef, i1 true>, <2 x i1> <i1 true, i1 true>, <2 x i1> %val
1011
ret <2 x i1> %val1

0 commit comments

Comments
 (0)