Roll r127459 back in:
authorCameron Zwarich <zwarich@apple.com>
Fri, 11 Mar 2011 21:52:04 +0000 (21:52 +0000)
committerCameron Zwarich <zwarich@apple.com>
Fri, 11 Mar 2011 21:52:04 +0000 (21:52 +0000)
Optimize trivial branches in CodeGenPrepare, which often get created from the
lowering of objectsize intrinsics. Unfortunately, a number of tests were relying
on llc not optimizing trivial branches, so I had to add an option to allow them
to continue to test what they originally tested.

This fixes <rdar://problem/8785296> and <rdar://problem/9112893>.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@127498 91177308-0d34-0410-b5e6-96231b3b80d8

16 files changed:
lib/Transforms/Scalar/CodeGenPrepare.cpp
test/CodeGen/ARM/constants.ll
test/CodeGen/CellSPU/jumptable.ll
test/CodeGen/Thumb/dyn-stackalloc.ll
test/CodeGen/Thumb2/2009-08-06-SpDecBug.ll
test/CodeGen/Thumb2/2009-09-28-ITBlockBug.ll
test/CodeGen/Thumb2/2010-11-22-EpilogueBug.ll
test/CodeGen/Thumb2/cross-rc-coalescing-2.ll
test/CodeGen/X86/2008-04-16-ReMatBug.ll
test/CodeGen/X86/MachineSink-PHIUse.ll
test/CodeGen/X86/personality.ll
test/CodeGen/X86/pr3366.ll
test/CodeGen/X86/sext-i1.ll
test/CodeGen/X86/zext-extract_subreg.ll
test/MC/ARM/simple-encoding.ll
test/Transforms/CodeGenPrepare/basic.ll

index 887fa9f004b35971062f49289ebb5b53a2c69d38..f0babcccee05c5384246518716fdd6aff34c5dd0 100644 (file)
@@ -58,6 +58,10 @@ STATISTIC(NumMemoryInsts, "Number of memory instructions whose address "
 STATISTIC(NumExtsMoved, "Number of [s|z]ext instructions combined with loads");
 STATISTIC(NumExtUses, "Number of uses of [s|z]ext instructions optimized");
 
+static cl::opt<bool> DisableBranchOpts(
+  "disable-cgp-branch-opts", cl::Hidden, cl::init(false),
+  cl::desc("Disable branch optimizations in CodeGenPrepare"));
+
 namespace {
   class CodeGenPrepare : public FunctionPass {
     /// TLI - Keep a pointer of a TargetLowering to consult for determining
@@ -130,6 +134,16 @@ bool CodeGenPrepare::runOnFunction(Function &F) {
 
   SunkAddrs.clear();
 
+  if (!DisableBranchOpts) {
+    MadeChange = false;
+    for (Function::iterator BB = F.begin(), E = F.end(); BB != E; ++BB)
+      MadeChange |= ConstantFoldTerminator(BB);
+
+    if (MadeChange && DT)
+      DT->DT->recalculate(F);
+    EverMadeChange |= MadeChange;
+  }
+
   return EverMadeChange;
 }
 
index 542cf02f2a90d14ee68fa87ef49bedd346d8bc25..a66ee41fe1993639b4364cc77a10ff8b6dcde410 100644 (file)
@@ -1,4 +1,4 @@
-; RUN: llc < %s -march=arm | FileCheck %s
+; RUN: llc < %s -march=arm -disable-cgp-branch-opts | FileCheck %s
 
 define i32 @f1() {
 ; CHECK: f1
index 42b41b3bf29b70b3114c09502a5f4bb45478dfeb..87376ef6ed53fdf9a010c5ccbf0bb385f8e08cf7 100644 (file)
@@ -1,4 +1,4 @@
-;RUN: llc --march=cellspu %s -o - | FileCheck %s
+;RUN: llc --march=cellspu -disable-cgp-branch-opts %s -o - | FileCheck %s
 ; This is to check that emitting jumptables doesn't crash llc
 define i32 @test(i32 %param) {
 entry:
index 1f31dca0524d49bc0eb693d390a5cf70cd88af51..e698e00641feaa2dec8bc59bb4f8a42584605101 100644 (file)
@@ -1,4 +1,4 @@
-; RUN: llc < %s -mtriple=thumb-apple-darwin | FileCheck %s
+; RUN: llc < %s -mtriple=thumb-apple-darwin -disable-cgp-branch-opts | FileCheck %s
 
        %struct.state = type { i32, %struct.info*, float**, i32, i32, i32, i32, i32, i32, i32, i32, i32, i64, i64, i64, i64, i64, i64, i8* }
        %struct.info = type { i32, i32, i32, i32, i32, i32, i32, i8* }
index 550b3efae998b525d7107443af8b43af42816a4d..ff68e665078af90e28afdcaa6e3e8d4cf354643e 100644 (file)
@@ -8,7 +8,7 @@ entry:
 ; CHECK: sub sp, #8
 ; CHECK: push
 ; CHECK: add r7, sp, #4
-; CHECK: subs r4, r7, #4
+; CHECK: sub.w r4, r7, #4
 ; CHECK: mov sp, r4
 ; CHECK-NOT: mov sp, r7
 ; CHECK: add sp, #8
index b2ed8fc7a67c7e46391359cbcf1f36fc3d55227c..ac3e80a7c113af3aa0ca2f7b30f0c8b43d739b3b 100644 (file)
@@ -1,4 +1,4 @@
-; RUN: llc < %s -mtriple=thumbv7-apple-darwin -mcpu=cortex-a8 | FileCheck %s
+; RUN: llc < %s -mtriple=thumbv7-apple-darwin -mcpu=cortex-a8 -disable-cgp-branch-opts | FileCheck %s
 
 %struct.pix_pos = type { i32, i32, i32, i32, i32, i32 }
 
index 313728c1b56abdcbda80976e7c95e71de90a39b7..d2140a10048d346cdc3b9160825a87a94eef64fd 100644 (file)
@@ -8,7 +8,7 @@ declare void @bar() nounwind optsize
 define void @foo() nounwind optsize {
 ; CHECK: foo:
 ; CHECK: push
-; CHECK: add r7, sp, #4
+; CHECK: mov r7, sp
 ; CHECK: sub sp, #4
 entry:
   %m.i = alloca %struct.buf*, align 4
index b8c8cb122a19bf1f779b20e98ba29cea26483c75..edbf83405be74789860e8435ef935c3b4236a0b4 100644 (file)
@@ -6,8 +6,6 @@ entry:
   br label %bb5
 
 bb5:                                              ; preds = %bb5, %entry
-; CHECK: %bb5
-; CHECK: bne
   br i1 undef, label %bb5, label %bb.nph
 
 bb.nph:                                           ; preds = %bb5
index 6e8891bfd5b8ba14e300cafcb40e259bc14979ff..bfe8ef53f565587916a0c37db64fac448d86693b 100644 (file)
@@ -1,4 +1,4 @@
-; RUN: llc < %s -mtriple=i386-apple-darwin | grep movw | not grep {, %e}
+; RUN: llc < %s -mtriple=i386-apple-darwin -disable-cgp-branch-opts | grep movw | not grep {, %e}
 
        %struct.DBC_t = type { i32, i8*, i16, %struct.DBC_t*, i8*, i8*, i8*, i8*, i8*, %struct.DBC_t*, i32, i32, i32, i32, i8*, i8*, i8*, i8*, i8*, i32, i32, i32, i32, i32, i32, i32, i32, i16, i16, i32*, i8, i16, %struct.DRVOPT*, i16 }
        %struct.DRVOPT = type { i16, i32, i8, %struct.DRVOPT* }
index 728e3773601895369c8bc6ec7ee3444e346504c8..3758fd8ce500ce5bb40799f4771c38e271e6b3e6 100644 (file)
@@ -1,4 +1,4 @@
-; RUN: llc < %s -mtriple=x86_64-appel-darwin -stats |& grep {machine-sink}
+; RUN: llc < %s -mtriple=x86_64-appel-darwin -disable-cgp-branch-opts -stats |& grep {machine-sink}
 
 define fastcc void @t() nounwind ssp {
 entry:
index 6789bb0c0fbe2a5c860ee367b40d1d9c9b47e564..705e489eb4c3e9dfafd8e0fac8a09279e6733410 100644 (file)
@@ -1,5 +1,5 @@
-; RUN: llc < %s -mtriple=x86_64-apple-darwin9 | FileCheck %s -check-prefix=X64
-; RUN: llc < %s -mtriple=i386-apple-darwin9 | FileCheck %s -check-prefix=X32
+; RUN: llc < %s -mtriple=x86_64-apple-darwin9 -disable-cgp-branch-opts | FileCheck %s -check-prefix=X64
+; RUN: llc < %s -mtriple=i386-apple-darwin9 -disable-cgp-branch-opts | FileCheck %s -check-prefix=X32
 ; PR1632
 
 define void @_Z1fv() {
index f813e2e58801ae9d0ea2c7e6589325b4ec14853d..1127b6093215b5c67efff74beb0361ee2687cf52 100644 (file)
@@ -1,4 +1,4 @@
-; RUN: llc < %s -march=x86 | grep movzbl
+; RUN: llc < %s -march=x86 -disable-cgp-branch-opts | grep movzbl
 ; PR3366
 
 define void @_ada_c34002a() nounwind {
index 21c418d534e9168b9f5e2fd11df8255e80fdb64b..574769b4308459f8cf7ba79f89921bfdfa8acf7f 100644 (file)
@@ -1,5 +1,5 @@
-; RUN: llc < %s -march=x86    | FileCheck %s -check-prefix=32
-; RUN: llc < %s -march=x86-64 | FileCheck %s -check-prefix=64
+; RUN: llc < %s -march=x86 -disable-cgp-branch-opts    | FileCheck %s -check-prefix=32
+; RUN: llc < %s -march=x86-64 -disable-cgp-branch-opts | FileCheck %s -check-prefix=64
 ; rdar://7573216
 ; PR6146
 
index e61e8805a2fdebcb3c5fb5754ba16e90c1c67c04..4f1dde3c4f0e3471731701790f175f5587ddfc49 100644 (file)
@@ -13,6 +13,7 @@ if.end:                                           ; preds = %if.end.i
 ; CHECK: %if.end
 ; CHECK: movl (%{{.*}}), [[REG:%[a-z]+]]
 ; CHECK-NOT: movl [[REG]], [[REG]]
+; CHECK-NEXT: testl [[REG]], [[REG]]
 ; CHECK-NEXT: xorb
   %tmp138 = select i1 undef, i32 0, i32 %tmp7.i
   %tmp867 = zext i32 %tmp138 to i64
index 0877e8e30c6f199d2099774eddd2000a302a34a5..defeea947d5aa4b27aa112b9e90a079cd0ac8408 100644 (file)
@@ -1,4 +1,4 @@
-;RUN: llc -mtriple=armv7-apple-darwin -show-mc-encoding < %s | FileCheck %s
+;RUN: llc -mtriple=armv7-apple-darwin -show-mc-encoding -disable-cgp-branch-opts < %s | FileCheck %s
 
 
 ;FIXME: Once the ARM integrated assembler is up and going, these sorts of tests
index 3b1fca328c5bc828357c68eba1f800a6b718fad2..ebf10f0e9df2ae3935ff880900baf7e4fe58019c 100644 (file)
@@ -14,13 +14,14 @@ entry:
   br i1 %1, label %T, label %trap
 
 ; CHECK: entry:
-; HECK-NEXT: ret i32 4
+; CHECK-NEXT: br label %T
 
 trap:                                             ; preds = %0, %entry
   tail call void @llvm.trap() noreturn nounwind
   unreachable
 
 T:
+; CHECK: ret i32 4
   ret i32 4
 }