[llvm] r273700 - Codegen: Fix broken assumption in Tail Merge.

Kyle Butt via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 24 11:16:37 PDT 2016


Author: iteratee
Date: Fri Jun 24 13:16:36 2016
New Revision: 273700

URL: http://llvm.org/viewvc/llvm-project?rev=273700&view=rev
Log:
Codegen: Fix broken assumption in Tail Merge.

Tail merge was making the assumption that a layout successor or
predecessor was always a cfg successor/predecessor. Remove that
assumption. Changes to tests are necessary because the errant cfg edges
were preventing optimizations.

Added:
    llvm/trunk/test/CodeGen/X86/tail-merge-unreachable.ll
Modified:
    llvm/trunk/lib/CodeGen/BranchFolding.cpp
    llvm/trunk/test/CodeGen/Mips/eh.ll
    llvm/trunk/test/CodeGen/SPARC/missinglabel.ll
    llvm/trunk/test/CodeGen/Thumb2/thumb2-cbnz.ll
    llvm/trunk/test/CodeGen/Thumb2/v8_IT_5.ll
    llvm/trunk/test/CodeGen/X86/br-fold.ll

Modified: llvm/trunk/lib/CodeGen/BranchFolding.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/BranchFolding.cpp?rev=273700&r1=273699&r2=273700&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/BranchFolding.cpp (original)
+++ llvm/trunk/lib/CodeGen/BranchFolding.cpp Fri Jun 24 13:16:36 2016
@@ -1255,7 +1255,7 @@ ReoptimizeBlock:
       // where a BB jumps to more than one landing pad.
       // TODO: Is it ever worth rewriting predecessors which don't already
       // jump to a landing pad, and so can safely jump to the fallthrough?
-    } else {
+    } else if (MBB->isSuccessor(&*FallThrough)) {
       // Rewrite all predecessors of the old block to go to the fallthrough
       // instead.
       while (!MBB->pred_empty()) {

Modified: llvm/trunk/test/CodeGen/Mips/eh.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/Mips/eh.ll?rev=273700&r1=273699&r2=273700&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/Mips/eh.ll (original)
+++ llvm/trunk/test/CodeGen/Mips/eh.ll Fri Jun 24 13:16:36 2016
@@ -24,7 +24,7 @@ entry:
 
 lpad:                                             ; preds = %entry
 ; CHECK-EL:  # %lpad
-; CHECK-EL:  beq $5
+; CHECK-EL:  bne $5
 
   %exn.val = landingpad { i8*, i32 }
            cleanup

Modified: llvm/trunk/test/CodeGen/SPARC/missinglabel.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/SPARC/missinglabel.ll?rev=273700&r1=273699&r2=273700&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/SPARC/missinglabel.ll (original)
+++ llvm/trunk/test/CodeGen/SPARC/missinglabel.ll Fri Jun 24 13:16:36 2016
@@ -4,14 +4,14 @@ target triple = "sparc64-unknown-linux-g
 
 define void @f() align 2 {
 entry:
-; CHECK: %xcc, .LBB0_1
+; CHECK: %xcc, .LBB0_2
   %cmp = icmp eq i64 undef, 0
   br i1 %cmp, label %targetblock, label %cond.false
 
 cond.false:
   unreachable
 
-; CHECK: .LBB0_1: ! %targetblock
+; CHECK: .LBB0_2: ! %targetblock
 targetblock:
   br i1 undef, label %cond.false.i83, label %exit.i85
 

Modified: llvm/trunk/test/CodeGen/Thumb2/thumb2-cbnz.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/Thumb2/thumb2-cbnz.ll?rev=273700&r1=273699&r2=273700&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/Thumb2/thumb2-cbnz.ll (original)
+++ llvm/trunk/test/CodeGen/Thumb2/thumb2-cbnz.ll Fri Jun 24 13:16:36 2016
@@ -5,6 +5,7 @@ declare double @foo(double) nounwind rea
 
 define void @t(i32 %c, double %b) {
 entry:
+; CHECK:      cmp	r0, #0
   %cmp1 = icmp ne i32 %c, 0
   br i1 %cmp1, label %bb3, label %bb1
 
@@ -23,8 +24,7 @@ bb7:
   br i1 %cmp3, label %bb11, label %bb9
 
 bb9:                                              ; preds = %bb7
-; CHECK:      cmp	r0, #0
-; CHECK-NEXT:      cbnz
+; CHECK:      cbnz
   %0 = tail call  double @foo(double %b) nounwind readnone ; <double> [#uses=0]
   br label %bb11
 

Modified: llvm/trunk/test/CodeGen/Thumb2/v8_IT_5.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/Thumb2/v8_IT_5.ll?rev=273700&r1=273699&r2=273700&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/Thumb2/v8_IT_5.ll (original)
+++ llvm/trunk/test/CodeGen/Thumb2/v8_IT_5.ll Fri Jun 24 13:16:36 2016
@@ -17,31 +17,13 @@
 
 define i32 @t(i32 %type) optsize {
 entry:
-  br i1 undef, label %if.then, label %if.else
-
-if.then:
-  unreachable
-
-if.else:
-  br i1 undef, label %if.then15, label %if.else18
-
-if.then15:
-  unreachable
-
-if.else18:
   switch i32 %type, label %if.else173 [
-    i32 3, label %if.then115
-    i32 1, label %if.then102
+    i32 13, label %if.then115
+    i32 6, label %if.then102
   ]
 
 if.then102:
-  br i1 undef, label %cond.true10.i, label %t.exit
-
-cond.true10.i:
-  br label %t.exit
-
-t.exit:
-  unreachable
+ br label %if.then115
 
 if.then115:
   br i1 undef, label %if.else163, label %if.else145
@@ -62,4 +44,3 @@ if.else173:
 }
 
 declare hidden fastcc %struct.hc* @foo(%struct.hc* nocapture, i32) nounwind optsize
-

Modified: llvm/trunk/test/CodeGen/X86/br-fold.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/br-fold.ll?rev=273700&r1=273699&r2=273700&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/X86/br-fold.ll (original)
+++ llvm/trunk/test/CodeGen/X86/br-fold.ll Fri Jun 24 13:16:36 2016
@@ -5,9 +5,11 @@
 ; RUN: llc -mtriple=x86_64-scei-ps4 < %s | FileCheck -check-prefix=PS4 %s
 
 ; X64_DARWIN: orq
+; X64_DARWIN-NEXT: jne
 ; X64_DARWIN-NEXT: %bb8.i329
 
 ; X64_LINUX: orq %rax, %rcx
+; X64_LINUX-NEXT: jne
 ; X64_LINUX-NEXT: %bb8.i329
 
 ; X64_WINDOWS: orq %rax, %rcx

Added: llvm/trunk/test/CodeGen/X86/tail-merge-unreachable.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/tail-merge-unreachable.ll?rev=273700&view=auto
==============================================================================
--- llvm/trunk/test/CodeGen/X86/tail-merge-unreachable.ll (added)
+++ llvm/trunk/test/CodeGen/X86/tail-merge-unreachable.ll Fri Jun 24 13:16:36 2016
@@ -0,0 +1,34 @@
+; RUN: llc -mtriple=x86_64-linux-gnu %s -o - -verify-machineinstrs | FileCheck %s
+
+define i32 @tail_merge_unreachable(i32 %i) {
+entry:
+  br i1 undef, label %sw, label %end
+sw:
+  switch i32 %i, label %end [
+    i32 99,  label %sw.bb
+    i32 98,  label %sw.bb
+    i32 101, label %sw.bb
+    i32 97,  label %sw.bb2
+    i32 96,  label %sw.bb2
+    i32 100, label %sw.bb2
+  ]
+sw.bb:
+  unreachable
+sw.bb2:
+  unreachable
+end:
+  %p = phi i32 [ 1, %sw ], [ 0, %entry ]
+  ret i32 %p
+
+; CHECK-LABEL: tail_merge_unreachable:
+; Range Check
+; CHECK: addl $-96
+; CHECK: cmpl $5
+; CHECK: jbe [[JUMP_TABLE_BLOCK:[.][A-Za-z0-9_]+]]
+; CHECK: retq
+; CHECK: [[JUMP_TABLE_BLOCK]]:
+; CHECK: btl
+; CHECK: jae [[UNREACHABLE_BLOCK:[.][A-Za-z0-9_]+]]
+; CHECK [[UNREACHABLE_BLOCK]]:
+; CHECK: .Lfunc_end0
+}




More information about the llvm-commits mailing list