[llvm] r182038 - DAGCombine: Also shrink eq compares where the constant is exactly as large as the smaller type.

Kostya Serebryany kcc at google.com
Tue May 21 00:19:02 PDT 2013


This causes http://llvm.org/bugs/show_bug.cgi?id=16083

long long a;
int b;
int fn1 () {
  return b || 0 & a;
}


% clang  -cc1 -triple i386-unknown-linux-gnu -emit-obj -x c bit.c

clang: llvm/lib/IR/Type.cpp:306: static llvm::IntegerType
*llvm::IntegerType::get(llvm::LLVMContext &, unsigned int): Assertion
`NumBits >= MIN_INT_BITS && "bitwidth too small"' failed.



On Thu, May 16, 2013 at 10:47 PM, Benjamin Kramer
<benny.kra at googlemail.com>wrote:

> Author: d0k
> Date: Thu May 16 13:47:58 2013
> New Revision: 182038
>
> URL: http://llvm.org/viewvc/llvm-project?rev=182038&view=rev
> Log:
> DAGCombine: Also shrink eq compares where the constant is exactly as large
> as the smaller type.
>
> if ((x & 255) == 255)
>
> before: movzbl  %al, %eax
>         cmpl  $255, %eax
>
> after:  cmpb  $-1, %al
>
> Modified:
>     llvm/trunk/lib/CodeGen/SelectionDAG/TargetLowering.cpp
>     llvm/trunk/test/CodeGen/X86/shrink-compare.ll
>
> Modified: llvm/trunk/lib/CodeGen/SelectionDAG/TargetLowering.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/TargetLowering.cpp?rev=182038&r1=182037&r2=182038&view=diff
>
> ==============================================================================
> --- llvm/trunk/lib/CodeGen/SelectionDAG/TargetLowering.cpp (original)
> +++ llvm/trunk/lib/CodeGen/SelectionDAG/TargetLowering.cpp Thu May 16
> 13:47:58 2013
> @@ -1160,7 +1160,7 @@ TargetLowering::SimplifySetCC(EVT VT, SD
>        }
>
>        // Make sure we're not losing bits from the constant.
> -      if (MinBits < C1.getBitWidth() && MinBits > C1.getActiveBits()) {
> +      if (MinBits < C1.getBitWidth() && MinBits >= C1.getActiveBits()) {
>          EVT MinVT = EVT::getIntegerVT(*DAG.getContext(), MinBits);
>          if (isTypeDesirableForOp(ISD::SETCC, MinVT)) {
>            // Will get folded away.
>
> Modified: llvm/trunk/test/CodeGen/X86/shrink-compare.ll
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/shrink-compare.ll?rev=182038&r1=182037&r2=182038&view=diff
>
> ==============================================================================
> --- llvm/trunk/test/CodeGen/X86/shrink-compare.ll (original)
> +++ llvm/trunk/test/CodeGen/X86/shrink-compare.ll Thu May 16 13:47:58 2013
> @@ -34,3 +34,19 @@ if.end:
>  ; CHECK: test2:
>  ; CHECK: cmpb $47, %{{dil|cl}}
>  }
> +
> +define void @test3(i32 %X) nounwind {
> +entry:
> +  %and = and i32 %X, 255
> +  %cmp = icmp eq i32 %and, 255
> +  br i1 %cmp, label %if.then, label %if.end
> +
> +if.then:
> +  tail call void @bar() nounwind
> +  br label %if.end
> +
> +if.end:
> +  ret void
> +; CHECK: test3:
> +; CHECK: cmpb $-1, %{{dil|cl}}
> +}
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130521/1f4945a4/attachment.html>


More information about the llvm-commits mailing list