[llvm-commits] [llvm] r152002 - in /llvm/trunk: lib/Transforms/Scalar/CodeGenPrepare.cpp test/CodeGen/ARM/2011-03-15-LdStMultipleBug.ll test/CodeGen/ARM/cse-libcalls.ll test/CodeGen/X86/2011-11-09-FoldImpDefs.ll test/CodeGen/X86/unreachable-stack-protector.ll

Bill Wendling isanbard at gmail.com
Sun Mar 4 02:46:02 PST 2012


Author: void
Date: Sun Mar  4 04:46:01 2012
New Revision: 152002

URL: http://llvm.org/viewvc/llvm-project?rev=152002&view=rev
Log:
Do trivial CSE of dead BBs during codegen preparation.

Some BBs can become dead after codegen preparation. If we delete them here, it
could help enable tail-call optimizations later on.
<rdar://problem/10256573>

Modified:
    llvm/trunk/lib/Transforms/Scalar/CodeGenPrepare.cpp
    llvm/trunk/test/CodeGen/ARM/2011-03-15-LdStMultipleBug.ll
    llvm/trunk/test/CodeGen/ARM/cse-libcalls.ll
    llvm/trunk/test/CodeGen/X86/2011-11-09-FoldImpDefs.ll
    llvm/trunk/test/CodeGen/X86/unreachable-stack-protector.ll

Modified: llvm/trunk/lib/Transforms/Scalar/CodeGenPrepare.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/CodeGenPrepare.cpp?rev=152002&r1=152001&r2=152002&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/CodeGenPrepare.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/CodeGenPrepare.cpp Sun Mar  4 04:46:01 2012
@@ -65,6 +65,11 @@
   "disable-cgp-branch-opts", cl::Hidden, cl::init(false),
   cl::desc("Disable branch optimizations in CodeGenPrepare"));
 
+// FIXME: Remove this abomination once all of the tests pass without it!
+static cl::opt<bool> DisableDeleteDeadBlocks(
+  "disable-cgp-delete-dead-blocks", cl::Hidden, cl::init(false),
+  cl::desc("Disable deleting dead blocks in CodeGenPrepare"));
+
 namespace {
   class CodeGenPrepare : public FunctionPass {
     /// TLI - Keep a pointer of a TargetLowering to consult for determining
@@ -160,8 +165,22 @@
 
   if (!DisableBranchOpts) {
     MadeChange = false;
-    for (Function::iterator BB = F.begin(), E = F.end(); BB != E; ++BB)
+    SmallPtrSet<BasicBlock*, 8> WorkList;
+    for (Function::iterator BB = F.begin(), E = F.end(); BB != E; ++BB) {
+      SmallVector<BasicBlock*, 2> Successors(succ_begin(BB), succ_end(BB));
       MadeChange |= ConstantFoldTerminator(BB, true);
+      if (!MadeChange) continue;
+
+      for (SmallVectorImpl<BasicBlock*>::iterator
+             II = Successors.begin(), IE = Successors.end(); II != IE; ++II)
+        if (pred_begin(*II) == pred_end(*II))
+          WorkList.insert(*II);
+    }
+
+    if (!DisableDeleteDeadBlocks)
+      for (SmallPtrSet<BasicBlock*, 8>::iterator
+             I = WorkList.begin(), E = WorkList.end(); I != E; ++I)
+        DeleteDeadBlock(*I);
 
     if (MadeChange)
       ModifiedDT = true;

Modified: llvm/trunk/test/CodeGen/ARM/2011-03-15-LdStMultipleBug.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/ARM/2011-03-15-LdStMultipleBug.ll?rev=152002&r1=152001&r2=152002&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/ARM/2011-03-15-LdStMultipleBug.ll (original)
+++ llvm/trunk/test/CodeGen/ARM/2011-03-15-LdStMultipleBug.ll Sun Mar  4 04:46:01 2012
@@ -1,4 +1,4 @@
-; RUN: llc < %s -mtriple=thumbv7-apple-darwin10 -relocation-model=pic -disable-fp-elim -mcpu=cortex-a8 | FileCheck %s
+; RUN: llc < %s -mtriple=thumbv7-apple-darwin10 -relocation-model=pic -disable-fp-elim -disable-cgp-delete-dead-blocks -mcpu=cortex-a8 | FileCheck %s
 
 ; Do not form Thumb2 ldrd / strd if the offset is not multiple of 4.
 ; rdar://9133587

Modified: llvm/trunk/test/CodeGen/ARM/cse-libcalls.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/ARM/cse-libcalls.ll?rev=152002&r1=152001&r2=152002&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/ARM/cse-libcalls.ll (original)
+++ llvm/trunk/test/CodeGen/ARM/cse-libcalls.ll Sun Mar  4 04:46:01 2012
@@ -4,7 +4,7 @@
 
 ; Without CSE of libcalls, there are two calls in the output instead of one.
 
-define i32 @u_f_nonbon(double %lambda) nounwind {
+define double @u_f_nonbon(double %lambda) nounwind {
 entry:
 	%tmp19.i.i = load double* null, align 4		; <double> [#uses=2]
 	%tmp6.i = fcmp olt double %tmp19.i.i, 1.000000e+00		; <i1> [#uses=1]
@@ -26,5 +26,5 @@
 	br i1 false, label %bb.nph53.i, label %bb508.i
 
 bb508.i:		; preds = %bb502.loopexit.i, %entry
-	ret i32 1
+	ret double %tmp10.i4
 }

Modified: llvm/trunk/test/CodeGen/X86/2011-11-09-FoldImpDefs.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/2011-11-09-FoldImpDefs.ll?rev=152002&r1=152001&r2=152002&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/X86/2011-11-09-FoldImpDefs.ll (original)
+++ llvm/trunk/test/CodeGen/X86/2011-11-09-FoldImpDefs.ll Sun Mar  4 04:46:01 2012
@@ -1,4 +1,4 @@
-; RUN: llc < %s -verify-regalloc | FileCheck %s
+; RUN: llc < %s -disable-cgp-delete-dead-blocks -verify-regalloc | FileCheck %s
 ; PR11347
 ;
 ; This test case materializes the constant 1 in a register:

Modified: llvm/trunk/test/CodeGen/X86/unreachable-stack-protector.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/unreachable-stack-protector.ll?rev=152002&r1=152001&r2=152002&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/X86/unreachable-stack-protector.ll (original)
+++ llvm/trunk/test/CodeGen/X86/unreachable-stack-protector.ll Sun Mar  4 04:46:01 2012
@@ -1,4 +1,4 @@
-; RUN: llc < %s | FileCheck %s
+; RUN: llc < %s -disable-cgp-delete-dead-blocks | FileCheck %s
 target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
 target triple = "x86_64-apple-darwin10.0.0"
 





More information about the llvm-commits mailing list