[llvm-commits] [llvm] r92408 - in /llvm/trunk: lib/Transforms/Scalar/InstructionCombining.cpp test/Transforms/InstCombine/or.ll

Nick Lewycky nicholas at mxc.ca
Fri Jan 1 18:56:27 PST 2010


Chris Lattner wrote:
> Author: lattner
> Date: Fri Jan  1 18:31:05 2010
> New Revision: 92408
>
> URL: http://llvm.org/viewvc/llvm-project?rev=92408&view=rev
> Log:
> remove the instcombine transformations that are inserting nasty
> pointer to int casts that confuse later optimizations.  See PR3351
> for details.
>
> This improves but doesn't complete fix 483.xalancbmk because llvm-gcc
> does this xform in GCC's "fold" routine as well.  Clang++ will do
> better I guess.
>   
So do we want instcombine to turn '((ptrtoint P) or (ptrtoint Q)) == 
null' into '(P == null) and (Q == null)'?

Operating under the assumption that we do, I've prepared a patch, attached.

Nick
> Modified:
>     llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp
>     llvm/trunk/test/Transforms/InstCombine/or.ll
>
> Modified: llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp?rev=92408&r1=92407&r2=92408&view=diff
>
> ==============================================================================
> --- llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp (original)
> +++ llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp Fri Jan  1 18:31:05 2010
> @@ -4166,21 +4166,6 @@
>  /// FoldAndOfICmps - Fold (icmp)&(icmp) if possible.
>  Instruction *InstCombiner::FoldAndOfICmps(Instruction &I,
>                                            ICmpInst *LHS, ICmpInst *RHS) {
> -  // (icmp eq A, null) & (icmp eq B, null) -->
> -  //     (icmp eq (ptrtoint(A)|ptrtoint(B)), 0)
> -  if (TD &&
> -      LHS->getPredicate() == ICmpInst::ICMP_EQ &&
> -      RHS->getPredicate() == ICmpInst::ICMP_EQ &&
> -      isa<ConstantPointerNull>(LHS->getOperand(1)) &&
> -      isa<ConstantPointerNull>(RHS->getOperand(1))) {
> -    const Type *IntPtrTy = TD->getIntPtrType(I.getContext());
> -    Value *A = Builder->CreatePtrToInt(LHS->getOperand(0), IntPtrTy);
> -    Value *B = Builder->CreatePtrToInt(RHS->getOperand(0), IntPtrTy);
> -    Value *NewOr = Builder->CreateOr(A, B);
> -    return new ICmpInst(ICmpInst::ICMP_EQ, NewOr,
> -                        Constant::getNullValue(IntPtrTy));
> -  }
> -  
>    Value *Val, *Val2;
>    ConstantInt *LHSCst, *RHSCst;
>    ICmpInst::Predicate LHSCC, RHSCC;
> @@ -4861,21 +4846,6 @@
>  /// FoldOrOfICmps - Fold (icmp)|(icmp) if possible.
>  Instruction *InstCombiner::FoldOrOfICmps(Instruction &I,
>                                           ICmpInst *LHS, ICmpInst *RHS) {
> -  // (icmp ne A, null) | (icmp ne B, null) -->
> -  //     (icmp ne (ptrtoint(A)|ptrtoint(B)), 0)
> -  if (TD &&
> -      LHS->getPredicate() == ICmpInst::ICMP_NE &&
> -      RHS->getPredicate() == ICmpInst::ICMP_NE &&
> -      isa<ConstantPointerNull>(LHS->getOperand(1)) &&
> -      isa<ConstantPointerNull>(RHS->getOperand(1))) {
> -    const Type *IntPtrTy = TD->getIntPtrType(I.getContext());
> -    Value *A = Builder->CreatePtrToInt(LHS->getOperand(0), IntPtrTy);
> -    Value *B = Builder->CreatePtrToInt(RHS->getOperand(0), IntPtrTy);
> -    Value *NewOr = Builder->CreateOr(A, B);
> -    return new ICmpInst(ICmpInst::ICMP_NE, NewOr,
> -                        Constant::getNullValue(IntPtrTy));
> -  }
> -  
>    Value *Val, *Val2;
>    ConstantInt *LHSCst, *RHSCst;
>    ICmpInst::Predicate LHSCC, RHSCC;
>
> Modified: llvm/trunk/test/Transforms/InstCombine/or.ll
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/or.ll?rev=92408&r1=92407&r2=92408&view=diff
>
> ==============================================================================
> --- llvm/trunk/test/Transforms/InstCombine/or.ll (original)
> +++ llvm/trunk/test/Transforms/InstCombine/or.ll Fri Jan  1 18:31:05 2010
> @@ -269,21 +269,6 @@
>  }
>  
>  ; PR5634
> -define i1 @test27(i32* %A, i32* %B) {
> -        %C1 = icmp eq i32* %A, null
> -        %C2 = icmp eq i32* %B, null
> -        ; (A == 0) & (A == 0)   -->   (A|B) == 0
> -        %D = and i1 %C1, %C2
> -        ret i1 %D
> -; CHECK: @test27
> -; CHECK: ptrtoint i32* %A
> -; CHECK: ptrtoint i32* %B
> -; CHECK: or i32 
> -; CHECK: icmp eq i32 {{.*}}, 0
> -; CHECK: ret i1 
> -}
> -
> -; PR5634
>  define i1 @test28(i32 %A, i32 %B) {
>          %C1 = icmp ne i32 %A, 0
>          %C2 = icmp ne i32 %B, 0
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>   

-------------- next part --------------
A non-text attachment was scrubbed...
Name: fold-or.patch
Type: text/x-patch
Size: 2373 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20100101/4a47c290/attachment.bin>


More information about the llvm-commits mailing list