Author: lattner
Date: Mon Feb 18 12:30:13 2008
New Revision: 47278

URL: http://llvm.org/viewvc/llvm-project?rev=47278&view=rev
Log:
Add a note about sext from i1 plus flags use.

Modified:
    llvm/trunk/lib/Target/X86/README.txt

Modified: llvm/trunk/lib/Target/X86/README.txt
URL: 
http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/README.txt?rev=47278&r1=47277&r2=47278&view=diff

==============================================================================
--- llvm/trunk/lib/Target/X86/README.txt (original)
+++ llvm/trunk/lib/Target/X86/README.txt Mon Feb 18 12:30:13 2008
@@ -1528,3 +1528,55 @@
 See PR2053 for more details.
 
 //===---------------------------------------------------------------------===//
+
+Consider:
+int test(unsigned long a, unsigned long b) { return -(a < b); }
+
+We currently compile this to:
+
+define i32 @test(i32 %a, i32 %b) nounwind  {
+       %tmp3 = icmp ult i32 %a, %b             ; <i1> [#uses=1]
+       %tmp34 = zext i1 %tmp3 to i32           ; <i32> [#uses=1]
+       %tmp5 = sub i32 0, %tmp34               ; <i32> [#uses=1]
+       ret i32 %tmp5
+}
+
+and
+
+_test:
+       movl    8(%esp), %eax
+       cmpl    %eax, 4(%esp)
+       setb    %al
+       movzbl  %al, %eax
+       negl    %eax
+       ret
+
+Several deficiencies here.  First, we should instcombine zext+neg into sext:
+
+define i32 @test2(i32 %a, i32 %b) nounwind  {
+       %tmp3 = icmp ult i32 %a, %b             ; <i1> [#uses=1]
+       %tmp34 = sext i1 %tmp3 to i32           ; <i32> [#uses=1]
+       ret i32 %tmp34
+}
+
+However, before we can do that, we have to fix the bad codegen that we get for
+sext from bool:
+
+_test2:
+       movl    8(%esp), %eax
+       cmpl    %eax, 4(%esp)
+       setb    %al
+       movzbl  %al, %eax
+       shll    $31, %eax
+       sarl    $31, %eax
+       ret
+
+This code should be at least as good as the code above.  Once this is fixed, we
+can optimize this specific case even more to:
+
+       movl    8(%esp), %eax
+       xorl    %ecx, %ecx
+        cmpl    %eax, 4(%esp)
+        sbbl    %ecx, %ecx
+
+//===---------------------------------------------------------------------===//


_______________________________________________
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits

Reply via email to