[llvm] r181586 - InstCombine: Verify the type before transforming uitofp into select.

Benjamin Kramer benny.kra at gmail.com
Fri May 10 03:10:53 PDT 2013


On 10.05.2013, at 11:16, Benjamin Kramer <benny.kra at googlemail.com> wrote:

> Author: d0k
> Date: Fri May 10 04:16:52 2013
> New Revision: 181586
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=181586&view=rev
> Log:
> InstCombine: Verify the type before transforming uitofp into select.

This fixes a bad regression in 3.3 and should be merged into the branch.

- Ben

> 
> PR15952.
> 
> Modified:
>    llvm/trunk/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
>    llvm/trunk/test/Transforms/InstCombine/add4.ll
> 
> Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp?rev=181586&r1=181585&r2=181586&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp (original)
> +++ llvm/trunk/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp Fri May 10 04:16:52 2013
> @@ -525,31 +525,32 @@ Instruction *InstCombiner::visitFMul(Bin
>     }
> 
>     // B * (uitofp i1 C) -> select C, B, 0
> -    if(I.hasNoNaNs() && I.hasNoInfs() && I.hasNoSignedZeros()) {
> -        Value *LHS=Op0, *RHS=Op1;
> -        Value *B, *C;
> -        if (!match(RHS, m_UIToFp(m_Value(C))))
> -            std::swap(LHS, RHS);
> +    if (I.hasNoNaNs() && I.hasNoInfs() && I.hasNoSignedZeros()) {
> +      Value *LHS = Op0, *RHS = Op1;
> +      Value *B, *C;
> +      if (!match(RHS, m_UIToFp(m_Value(C))))
> +        std::swap(LHS, RHS);
> 
> -        if (match(RHS, m_UIToFp(m_Value(C)))) {
> -            B=LHS;
> -            Value *Zero = ConstantFP::getNegativeZero(B->getType());
> -            return SelectInst::Create(C, B, Zero);
> -        }
> +      if (match(RHS, m_UIToFp(m_Value(C))) && C->getType()->isIntegerTy(1)) {
> +        B = LHS;
> +        Value *Zero = ConstantFP::getNegativeZero(B->getType());
> +        return SelectInst::Create(C, B, Zero);
> +      }
>     }
> 
>     // A * (1 - uitofp i1 C) -> select C, 0, A
> -    if(I.hasNoNaNs() && I.hasNoInfs() && I.hasNoSignedZeros()) { 
> -        Value *LHS=Op0, *RHS=Op1;
> -        Value *A, *C;
> -        if (!match(RHS, m_FSub(m_FPOne(), m_UIToFp(m_Value(C)))))
> -            std::swap(LHS, RHS);
> +    if (I.hasNoNaNs() && I.hasNoInfs() && I.hasNoSignedZeros()) {
> +      Value *LHS = Op0, *RHS = Op1;
> +      Value *A, *C;
> +      if (!match(RHS, m_FSub(m_FPOne(), m_UIToFp(m_Value(C)))))
> +        std::swap(LHS, RHS);
> 
> -        if (match(RHS, m_FSub(m_FPOne(), m_UIToFp(m_Value(C))))) {
> -            A=LHS;
> -            Value *Zero = ConstantFP::getNegativeZero(A->getType());
> -            return SelectInst::Create(C, Zero, A);
> -        }
> +      if (match(RHS, m_FSub(m_FPOne(), m_UIToFp(m_Value(C)))) &&
> +          C->getType()->isIntegerTy(1)) {
> +        A = LHS;
> +        Value *Zero = ConstantFP::getNegativeZero(A->getType());
> +        return SelectInst::Create(C, Zero, A);
> +      }
>     }
> 
>     if (!isa<Constant>(Op1))
> 
> Modified: llvm/trunk/test/Transforms/InstCombine/add4.ll
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/add4.ll?rev=181586&r1=181585&r2=181586&view=diff
> ==============================================================================
> --- llvm/trunk/test/Transforms/InstCombine/add4.ll (original)
> +++ llvm/trunk/test/Transforms/InstCombine/add4.ll Fri May 10 04:16:52 2013
> @@ -38,3 +38,21 @@ EntryBlock:
> ; CHECK: select i1 %C, float %B, float %A
> }
> 
> +; PR15952
> +define float @test4(float %A, float %B, i32 %C) {
> +  %cf = uitofp i32 %C to float
> +  %mc = fsub float 1.000000e+00, %cf
> +  %p1 = fmul fast float %A, %mc
> +  ret float %p1
> +; CHECK: @test4
> +; CHECK: uitofp
> +}
> +
> +define float @test5(float %A, float %B, i32 %C) {
> +  %cf = uitofp i32 %C to float
> +  %p2 = fmul fast float %B, %cf
> +  ret float %p2
> +; CHECK: @test5
> +; CHECK: uitofp
> +}
> +
> 
> 
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits





More information about the llvm-commits mailing list