[llvm-commits] [llvm] r85334 - in /llvm/trunk/lib/Target: README.txt X86/README.txt
Bill Wendling
isanbard at gmail.com
Tue Oct 27 15:48:32 PDT 2009
Author: void
Date: Tue Oct 27 17:48:31 2009
New Revision: 85334
URL: http://llvm.org/viewvc/llvm-project?rev=85334&view=rev
Log:
Move and clarify note.
Modified:
llvm/trunk/lib/Target/README.txt
llvm/trunk/lib/Target/X86/README.txt
Modified: llvm/trunk/lib/Target/README.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/README.txt?rev=85334&r1=85333&r2=85334&view=diff
==============================================================================
--- llvm/trunk/lib/Target/README.txt (original)
+++ llvm/trunk/lib/Target/README.txt Tue Oct 27 17:48:31 2009
@@ -1600,3 +1600,36 @@
//===---------------------------------------------------------------------===//
+int func(int a, int b) { if (a & 0x80) b |= 0x80; else b &= ~0x80; return b; }
+
+Generates this:
+
+define i32 @func(i32 %a, i32 %b) nounwind readnone ssp {
+entry:
+ %0 = and i32 %a, 128 ; <i32> [#uses=1]
+ %1 = icmp eq i32 %0, 0 ; <i1> [#uses=1]
+ %2 = or i32 %b, 128 ; <i32> [#uses=1]
+ %3 = and i32 %b, -129 ; <i32> [#uses=1]
+ %b_addr.0 = select i1 %1, i32 %3, i32 %2 ; <i32> [#uses=1]
+ ret i32 %b_addr.0
+}
+
+However, it's functionally equivalent to:
+
+ b = (b & ~0x80) | (a & 0x80);
+
+Which generates this:
+
+define i32 @func(i32 %a, i32 %b) nounwind readnone ssp {
+entry:
+ %0 = and i32 %b, -129 ; <i32> [#uses=1]
+ %1 = and i32 %a, 128 ; <i32> [#uses=1]
+ %2 = or i32 %0, %1 ; <i32> [#uses=1]
+ ret i32 %2
+}
+
+This can be generalized for other forms:
+
+ b = (b & ~0x80) | (a & 0x40) << 1;
+
+//===---------------------------------------------------------------------===//
Modified: llvm/trunk/lib/Target/X86/README.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/README.txt?rev=85334&r1=85333&r2=85334&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/README.txt (original)
+++ llvm/trunk/lib/Target/X86/README.txt Tue Oct 27 17:48:31 2009
@@ -1954,34 +1954,3 @@
information to add the "lock" prefix.
//===---------------------------------------------------------------------===//
-
-int func(int a, int b) { if (a & 0x80) b |= 0x80; else b &= ~0x80; return b; }
-
-Current:
-
-
- movb %sil, %al
- andb $127, %sil
- orb $-128, %al
- testb %dil, %dil
- js LBB1_2
- movb %sil, %al
-LBB1_2:
- movsbl %al, %eax
-
-
-Better:
-
- movl %esi, %eax
- orl $-128, %eax
- andl $127, %esi
- testb %dil, %dil
- cmovns %esi, %eax
- movsbl %al,%eax
-
-Best (recognize this as 'b = (b & ~0x80) | (a & 0x80)'):
-
- andb $-128, %dil
- andb $127, %sil
- orb %dil, %sil
- movsbl %sil, %eax
More information about the llvm-commits
mailing list