[llvm] r196611 - Don't use isNullValue to evaluate ConstantExpr

Alp Toker alp at nuanti.com
Sat Dec 7 02:01:32 PST 2013


Thanks Duncan, also fixes PR17077.

Bill, could you pull this into 3.4?

I guess Apple clang has been shipping with this patch for some time -- 
is there a public branch we could sift through to see if there are any 
other patches good to upstream?

Alp.



On 06/12/2013 21:48, Duncan P. N. Exon Smith wrote:
> Author: dexonsmith
> Date: Fri Dec  6 15:48:36 2013
> New Revision: 196611
>
> URL: http://llvm.org/viewvc/llvm-project?rev=196611&view=rev
> Log:
> Don't use isNullValue to evaluate ConstantExpr
>
> ConstantExpr can evaluate to false even when isNullValue gives false.
>
> Fixes PR18143.
>
> Added:
>      llvm/trunk/test/Transforms/InstCombine/phi-select-constexpr.ll
> Modified:
>      llvm/trunk/lib/Transforms/InstCombine/InstructionCombining.cpp
>
> Modified: llvm/trunk/lib/Transforms/InstCombine/InstructionCombining.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstructionCombining.cpp?rev=196611&r1=196610&r2=196611&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Transforms/InstCombine/InstructionCombining.cpp (original)
> +++ llvm/trunk/lib/Transforms/InstCombine/InstructionCombining.cpp Fri Dec  6 15:48:36 2013
> @@ -699,7 +699,10 @@ Instruction *InstCombiner::FoldOpIntoPhi
>         Value *TrueVInPred = TrueV->DoPHITranslation(PhiTransBB, ThisBB);
>         Value *FalseVInPred = FalseV->DoPHITranslation(PhiTransBB, ThisBB);
>         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;
>         else
>           InV = Builder->CreateSelect(PN->getIncomingValue(i),
>
> Added: llvm/trunk/test/Transforms/InstCombine/phi-select-constexpr.ll
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/phi-select-constexpr.ll?rev=196611&view=auto
> ==============================================================================
> --- llvm/trunk/test/Transforms/InstCombine/phi-select-constexpr.ll (added)
> +++ llvm/trunk/test/Transforms/InstCombine/phi-select-constexpr.ll Fri Dec  6 15:48:36 2013
> @@ -0,0 +1,19 @@
> +; RUN: opt < %s -S -instcombine | FileCheck %s
> + at A = extern_weak global i32, align 4
> + at 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
> +}
> +
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits

-- 
http://www.nuanti.com
the browser experts




More information about the llvm-commits mailing list