[llvm-commits] [llvm] r60068 - in /llvm/trunk: lib/Transforms/Scalar/CodeGenPrepare.cpp test/CodeGen/X86/2008-10-16-SpillerBug.ll test/CodeGen/X86/isel-sink2.ll
Chris Lattner
sabre at nondot.org
Tue Nov 25 16:26:17 PST 2008
Author: lattner
Date: Tue Nov 25 18:26:16 2008
New Revision: 60068
URL: http://llvm.org/viewvc/llvm-project?rev=60068&view=rev
Log:
Teach CodeGenPrepare to look through Bitcast instructions when attempting to
optimize addressing modes. This allows us to optimize things like isel-sink2.ll
into:
movl 4(%esp), %eax
cmpb $0, 4(%eax)
jne LBB1_2 ## F
LBB1_1: ## TB
movl $4, %eax
ret
LBB1_2: ## F
movzbl 7(%eax), %eax
ret
instead of:
_test:
movl 4(%esp), %eax
cmpb $0, 4(%eax)
leal 4(%eax), %eax
jne LBB1_2 ## F
LBB1_1: ## TB
movl $4, %eax
ret
LBB1_2: ## F
movzbl 3(%eax), %eax
ret
This shrinks (e.g.) 403.gcc from 1133510 to 1128345 lines of .s.
Note that the 2008-10-16-SpillerBug.ll testcase is dubious at best, I doubt
it is really testing what it thinks it is.
Added:
llvm/trunk/test/CodeGen/X86/isel-sink2.ll
Modified:
llvm/trunk/lib/Transforms/Scalar/CodeGenPrepare.cpp
llvm/trunk/test/CodeGen/X86/2008-10-16-SpillerBug.ll
Modified: llvm/trunk/lib/Transforms/Scalar/CodeGenPrepare.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/CodeGenPrepare.cpp?rev=60068&r1=60067&r2=60068&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/CodeGenPrepare.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/CodeGenPrepare.cpp Tue Nov 25 18:26:16 2008
@@ -636,6 +636,17 @@
TLI.getPointerTy())
return MatchAddr(AddrInst->getOperand(0), Depth);
return false;
+ case Instruction::BitCast:
+ // BitCast is always a noop, and we can handle it as long as it is
+ // int->int or pointer->pointer (we don't want int<->fp or something).
+ if ((isa<PointerType>(AddrInst->getOperand(0)->getType()) ||
+ isa<IntegerType>(AddrInst->getOperand(0)->getType())) &&
+ // Don't touch identity bitcasts. These were probably put here by LSR,
+ // and we don't want to mess around with them. Assume it knows what it
+ // is doing.
+ AddrInst->getOperand(0)->getType() != AddrInst->getType())
+ return MatchAddr(AddrInst->getOperand(0), Depth);
+ return false;
case Instruction::Add: {
// Check to see if we can merge in the RHS then the LHS. If so, we win.
ExtAddrMode BackupAddrMode = AddrMode;
Modified: llvm/trunk/test/CodeGen/X86/2008-10-16-SpillerBug.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/2008-10-16-SpillerBug.ll?rev=60068&r1=60067&r2=60068&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/X86/2008-10-16-SpillerBug.ll (original)
+++ llvm/trunk/test/CodeGen/X86/2008-10-16-SpillerBug.ll Tue Nov 25 18:26:16 2008
@@ -1,4 +1,4 @@
-; RUN: llvm-as < %s | llc -relocation-model=pic -disable-fp-elim -mtriple=i386-apple-darwin | grep and | grep 7 | grep ebp
+; RUN: llvm-as < %s | llc -relocation-model=pic -disable-fp-elim -mtriple=i386-apple-darwin | grep {andl.*7.*ecx}
%struct.XXDActiveTextureTargets = type { i64, i64, i64, i64, i64, i64 }
%struct.XXDAlphaTest = type { float, i16, i8, i8 }
Added: llvm/trunk/test/CodeGen/X86/isel-sink2.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/isel-sink2.ll?rev=60068&view=auto
==============================================================================
--- llvm/trunk/test/CodeGen/X86/isel-sink2.ll (added)
+++ llvm/trunk/test/CodeGen/X86/isel-sink2.ll Tue Nov 25 18:26:16 2008
@@ -0,0 +1,16 @@
+; RUN: llvm-as < %s | llc -march=x86 | grep {movzbl.7(%...)}
+; RUN: llvm-as < %s | llc -march=x86 | not grep leal
+
+define i8 @test(i32 *%P) nounwind {
+ %Q = getelementptr i32* %P, i32 1
+ %R = bitcast i32* %Q to i8*
+ %S = load i8* %R
+ %T = icmp eq i8 %S, 0
+ br i1 %T, label %TB, label %F
+TB:
+ ret i8 4
+F:
+ %U = getelementptr i8* %R, i32 3
+ %V = load i8* %U
+ ret i8 %V
+}
More information about the llvm-commits
mailing list