mirror of
https://github.com/RPCSX/llvm.git
synced 2025-02-04 19:38:22 +00:00
Don't use isNullValue to evaluate ConstantExpr
ConstantExpr can evaluate to false even when isNullValue gives false. Fixes PR18143. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@196611 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
92b10e5f85
commit
42883d0ac4
@ -699,7 +699,10 @@ Instruction *InstCombiner::FoldOpIntoPhi(Instruction &I) {
|
|||||||
Value *TrueVInPred = TrueV->DoPHITranslation(PhiTransBB, ThisBB);
|
Value *TrueVInPred = TrueV->DoPHITranslation(PhiTransBB, ThisBB);
|
||||||
Value *FalseVInPred = FalseV->DoPHITranslation(PhiTransBB, ThisBB);
|
Value *FalseVInPred = FalseV->DoPHITranslation(PhiTransBB, ThisBB);
|
||||||
Value *InV = 0;
|
Value *InV = 0;
|
||||||
if (Constant *InC = dyn_cast<Constant>(PN->getIncomingValue(i)))
|
// Beware of ConstantExpr: it may eventually evaluate to getNullValue,
|
||||||
|
// even if currently isNullValue gives false.
|
||||||
|
Constant *InC = dyn_cast<Constant>(PN->getIncomingValue(i));
|
||||||
|
if (InC && !isa<ConstantExpr>(InC))
|
||||||
InV = InC->isNullValue() ? FalseVInPred : TrueVInPred;
|
InV = InC->isNullValue() ? FalseVInPred : TrueVInPred;
|
||||||
else
|
else
|
||||||
InV = Builder->CreateSelect(PN->getIncomingValue(i),
|
InV = Builder->CreateSelect(PN->getIncomingValue(i),
|
||||||
|
19
test/Transforms/InstCombine/phi-select-constexpr.ll
Normal file
19
test/Transforms/InstCombine/phi-select-constexpr.ll
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
; RUN: opt < %s -S -instcombine | FileCheck %s
|
||||||
|
@A = extern_weak global i32, align 4
|
||||||
|
@B = extern_weak global i32, align 4
|
||||||
|
|
||||||
|
define i32 @foo(i1 %which) {
|
||||||
|
entry:
|
||||||
|
br i1 %which, label %final, label %delay
|
||||||
|
|
||||||
|
delay:
|
||||||
|
br label %final
|
||||||
|
|
||||||
|
; CHECK-LABEL: final:
|
||||||
|
; CHECK: phi i32 [ 1, %entry ], [ select (i1 icmp eq (i32* @A, i32* @B), i32 2, i32 1), %delay ]
|
||||||
|
final:
|
||||||
|
%use2 = phi i1 [ false, %entry ], [ icmp eq (i32* @A, i32* @B), %delay ]
|
||||||
|
%value = select i1 %use2, i32 2, i32 1
|
||||||
|
ret i32 %value
|
||||||
|
}
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user