forked from OSchip/llvm-project
Enable machine sinking critical edge splitting. e.g.
define double @foo(double %x, double %y, i1 %c) nounwind { %a = fdiv double %x, 3.2 %z = select i1 %c, double %a, double %y ret double %z } Was: _foo: divsd LCPI0_0(%rip), %xmm0 testb $1, %dil jne LBB0_2 movaps %xmm1, %xmm0 LBB0_2: ret Now: _foo: testb $1, %dil je LBB0_2 divsd LCPI0_0(%rip), %xmm0 ret LBB0_2: movaps %xmm1, %xmm0 ret This avoids the divsd when early exit is taken. rdar://8454886 llvm-svn: 114372
This commit is contained in:
parent
abb5a7370d
commit
f3e9a48584
|
@ -35,10 +35,7 @@ using namespace llvm;
|
||||||
static cl::opt<bool>
|
static cl::opt<bool>
|
||||||
SplitEdges("machine-sink-split",
|
SplitEdges("machine-sink-split",
|
||||||
cl::desc("Split critical edges during machine sinking"),
|
cl::desc("Split critical edges during machine sinking"),
|
||||||
cl::init(false), cl::Hidden);
|
cl::init(true), cl::Hidden);
|
||||||
static cl::opt<unsigned>
|
|
||||||
SplitLimit("split-limit",
|
|
||||||
cl::init(~0u), cl::Hidden);
|
|
||||||
|
|
||||||
STATISTIC(NumSunk, "Number of machine instructions sunk");
|
STATISTIC(NumSunk, "Number of machine instructions sunk");
|
||||||
STATISTIC(NumSplit, "Number of critical edges split");
|
STATISTIC(NumSplit, "Number of critical edges split");
|
||||||
|
@ -311,7 +308,7 @@ MachineBasicBlock *MachineSinking::SplitCriticalEdge(MachineInstr *MI,
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
// Avoid breaking back edge. From == To means backedge for single BB loop.
|
// Avoid breaking back edge. From == To means backedge for single BB loop.
|
||||||
if (!SplitEdges || NumSplit == SplitLimit || FromBB == ToBB)
|
if (!SplitEdges || FromBB == ToBB)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
// Check for backedges of more "complex" loops.
|
// Check for backedges of more "complex" loops.
|
||||||
|
@ -561,8 +558,6 @@ bool MachineSinking::SinkInstruction(MachineInstr *MI, bool &SawStore) {
|
||||||
// BreakPHIEdge is true if all the uses are in the successor MBB being
|
// BreakPHIEdge is true if all the uses are in the successor MBB being
|
||||||
// sunken into and they are all PHI nodes. In this case, machine-sink must
|
// sunken into and they are all PHI nodes. In this case, machine-sink must
|
||||||
// break the critical edge first.
|
// break the critical edge first.
|
||||||
if (NumSplit == SplitLimit)
|
|
||||||
return false;
|
|
||||||
MachineBasicBlock *NewSucc = SplitCriticalEdge(MI, ParentBlock,
|
MachineBasicBlock *NewSucc = SplitCriticalEdge(MI, ParentBlock,
|
||||||
SuccToSinkTo, BreakPHIEdge);
|
SuccToSinkTo, BreakPHIEdge);
|
||||||
if (!NewSucc) {
|
if (!NewSucc) {
|
||||||
|
|
|
@ -9,12 +9,12 @@ entry:
|
||||||
volatile store i32 0, i32* %c, align 4
|
volatile store i32 0, i32* %c, align 4
|
||||||
%0 = volatile load i32* %a, align 4 ; <i32> [#uses=1]
|
%0 = volatile load i32* %a, align 4 ; <i32> [#uses=1]
|
||||||
%1 = icmp eq i32 %0, 0 ; <i1> [#uses=1]
|
%1 = icmp eq i32 %0, 0 ; <i1> [#uses=1]
|
||||||
; CHECK: addiu $4, $zero, 3
|
; CHECK: addiu $3, $zero, 0
|
||||||
%iftmp.0.0 = select i1 %1, i32 3, i32 0 ; <i32> [#uses=1]
|
%iftmp.0.0 = select i1 %1, i32 3, i32 0 ; <i32> [#uses=1]
|
||||||
%2 = volatile load i32* %c, align 4 ; <i32> [#uses=1]
|
%2 = volatile load i32* %c, align 4 ; <i32> [#uses=1]
|
||||||
%3 = icmp eq i32 %2, 0 ; <i1> [#uses=1]
|
%3 = icmp eq i32 %2, 0 ; <i1> [#uses=1]
|
||||||
; CHECK: addu $4, $zero, $3
|
; CHECK: addiu $3, $zero, 3
|
||||||
; CHECK: addu $2, $5, $4
|
; CHECK: addu $2, $5, $3
|
||||||
%iftmp.2.0 = select i1 %3, i32 0, i32 5 ; <i32> [#uses=1]
|
%iftmp.2.0 = select i1 %3, i32 0, i32 5 ; <i32> [#uses=1]
|
||||||
%4 = add nsw i32 %iftmp.2.0, %iftmp.0.0 ; <i32> [#uses=1]
|
%4 = add nsw i32 %iftmp.2.0, %iftmp.0.0 ; <i32> [#uses=1]
|
||||||
ret i32 %4
|
ret i32 %4
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
|
|
||||||
; CHECK: oeq_inff:
|
; CHECK: oeq_inff:
|
||||||
; CHECK: ucomiss
|
; CHECK: ucomiss
|
||||||
; CHECK: jae
|
; CHECK: jb
|
||||||
define float @oeq_inff(float %x, float %y) nounwind readonly {
|
define float @oeq_inff(float %x, float %y) nounwind readonly {
|
||||||
%t0 = fcmp oeq float %x, 0x7FF0000000000000
|
%t0 = fcmp oeq float %x, 0x7FF0000000000000
|
||||||
%t1 = select i1 %t0, float 1.0, float %y
|
%t1 = select i1 %t0, float 1.0, float %y
|
||||||
|
@ -14,7 +14,7 @@ define float @oeq_inff(float %x, float %y) nounwind readonly {
|
||||||
|
|
||||||
; CHECK: oeq_inf:
|
; CHECK: oeq_inf:
|
||||||
; CHECK: ucomisd
|
; CHECK: ucomisd
|
||||||
; CHECK: jae
|
; CHECK: jb
|
||||||
define double @oeq_inf(double %x, double %y) nounwind readonly {
|
define double @oeq_inf(double %x, double %y) nounwind readonly {
|
||||||
%t0 = fcmp oeq double %x, 0x7FF0000000000000
|
%t0 = fcmp oeq double %x, 0x7FF0000000000000
|
||||||
%t1 = select i1 %t0, double 1.0, double %y
|
%t1 = select i1 %t0, double 1.0, double %y
|
||||||
|
@ -23,7 +23,7 @@ define double @oeq_inf(double %x, double %y) nounwind readonly {
|
||||||
|
|
||||||
; CHECK: une_inff:
|
; CHECK: une_inff:
|
||||||
; CHECK: ucomiss
|
; CHECK: ucomiss
|
||||||
; CHECK: jb
|
; CHECK: jae
|
||||||
define float @une_inff(float %x, float %y) nounwind readonly {
|
define float @une_inff(float %x, float %y) nounwind readonly {
|
||||||
%t0 = fcmp une float %x, 0x7FF0000000000000
|
%t0 = fcmp une float %x, 0x7FF0000000000000
|
||||||
%t1 = select i1 %t0, float 1.0, float %y
|
%t1 = select i1 %t0, float 1.0, float %y
|
||||||
|
@ -32,7 +32,7 @@ define float @une_inff(float %x, float %y) nounwind readonly {
|
||||||
|
|
||||||
; CHECK: une_inf:
|
; CHECK: une_inf:
|
||||||
; CHECK: ucomisd
|
; CHECK: ucomisd
|
||||||
; CHECK: jb
|
; CHECK: jae
|
||||||
define double @une_inf(double %x, double %y) nounwind readonly {
|
define double @une_inf(double %x, double %y) nounwind readonly {
|
||||||
%t0 = fcmp une double %x, 0x7FF0000000000000
|
%t0 = fcmp une double %x, 0x7FF0000000000000
|
||||||
%t1 = select i1 %t0, double 1.0, double %y
|
%t1 = select i1 %t0, double 1.0, double %y
|
||||||
|
@ -41,7 +41,7 @@ define double @une_inf(double %x, double %y) nounwind readonly {
|
||||||
|
|
||||||
; CHECK: oeq_neg_inff:
|
; CHECK: oeq_neg_inff:
|
||||||
; CHECK: ucomiss
|
; CHECK: ucomiss
|
||||||
; CHECK: jae
|
; CHECK: jb
|
||||||
define float @oeq_neg_inff(float %x, float %y) nounwind readonly {
|
define float @oeq_neg_inff(float %x, float %y) nounwind readonly {
|
||||||
%t0 = fcmp oeq float %x, 0xFFF0000000000000
|
%t0 = fcmp oeq float %x, 0xFFF0000000000000
|
||||||
%t1 = select i1 %t0, float 1.0, float %y
|
%t1 = select i1 %t0, float 1.0, float %y
|
||||||
|
@ -50,7 +50,7 @@ define float @oeq_neg_inff(float %x, float %y) nounwind readonly {
|
||||||
|
|
||||||
; CHECK: oeq_neg_inf:
|
; CHECK: oeq_neg_inf:
|
||||||
; CHECK: ucomisd
|
; CHECK: ucomisd
|
||||||
; CHECK: jae
|
; CHECK: jb
|
||||||
define double @oeq_neg_inf(double %x, double %y) nounwind readonly {
|
define double @oeq_neg_inf(double %x, double %y) nounwind readonly {
|
||||||
%t0 = fcmp oeq double %x, 0xFFF0000000000000
|
%t0 = fcmp oeq double %x, 0xFFF0000000000000
|
||||||
%t1 = select i1 %t0, double 1.0, double %y
|
%t1 = select i1 %t0, double 1.0, double %y
|
||||||
|
@ -59,7 +59,7 @@ define double @oeq_neg_inf(double %x, double %y) nounwind readonly {
|
||||||
|
|
||||||
; CHECK: une_neg_inff:
|
; CHECK: une_neg_inff:
|
||||||
; CHECK: ucomiss
|
; CHECK: ucomiss
|
||||||
; CHECK: jb
|
; CHECK: jae
|
||||||
define float @une_neg_inff(float %x, float %y) nounwind readonly {
|
define float @une_neg_inff(float %x, float %y) nounwind readonly {
|
||||||
%t0 = fcmp une float %x, 0xFFF0000000000000
|
%t0 = fcmp une float %x, 0xFFF0000000000000
|
||||||
%t1 = select i1 %t0, float 1.0, float %y
|
%t1 = select i1 %t0, float 1.0, float %y
|
||||||
|
@ -68,7 +68,7 @@ define float @une_neg_inff(float %x, float %y) nounwind readonly {
|
||||||
|
|
||||||
; CHECK: une_neg_inf:
|
; CHECK: une_neg_inf:
|
||||||
; CHECK: ucomisd
|
; CHECK: ucomisd
|
||||||
; CHECK: jb
|
; CHECK: jae
|
||||||
define double @une_neg_inf(double %x, double %y) nounwind readonly {
|
define double @une_neg_inf(double %x, double %y) nounwind readonly {
|
||||||
%t0 = fcmp une double %x, 0xFFF0000000000000
|
%t0 = fcmp une double %x, 0xFFF0000000000000
|
||||||
%t1 = select i1 %t0, double 1.0, double %y
|
%t1 = select i1 %t0, double 1.0, double %y
|
||||||
|
|
|
@ -6,10 +6,11 @@
|
||||||
; that it's conditionally evaluated.
|
; that it's conditionally evaluated.
|
||||||
|
|
||||||
; CHECK: foo:
|
; CHECK: foo:
|
||||||
; CHECK: divsd
|
|
||||||
; CHECK-NEXT: testb $1, %dil
|
; CHECK-NEXT: testb $1, %dil
|
||||||
; CHECK-NEXT: jne
|
; CHECK-NEXT: je
|
||||||
; CHECK-NEXT: divsd
|
; CHECK-NEXT: divsd
|
||||||
|
; CHECK-NEXT: ret
|
||||||
|
; CHECK: divsd
|
||||||
|
|
||||||
define double @foo(double %x, double %y, i1 %c) nounwind {
|
define double @foo(double %x, double %y, i1 %c) nounwind {
|
||||||
%a = fdiv double %x, 3.2
|
%a = fdiv double %x, 3.2
|
||||||
|
@ -18,6 +19,24 @@ define double @foo(double %x, double %y, i1 %c) nounwind {
|
||||||
ret double %z
|
ret double %z
|
||||||
}
|
}
|
||||||
|
|
||||||
|
; Make sure the critical edge is broken so the divsd is sunken below
|
||||||
|
; the conditional branch.
|
||||||
|
; rdar://8454886
|
||||||
|
|
||||||
|
; CHECK: split:
|
||||||
|
; CHECK-NEXT: testb $1, %dil
|
||||||
|
; CHECK-NEXT: je
|
||||||
|
; CHECK-NEXT: divsd
|
||||||
|
; CHECK-NEXT: ret
|
||||||
|
; CHECK: movaps
|
||||||
|
; CHECK-NEXT: ret
|
||||||
|
define double @split(double %x, double %y, i1 %c) nounwind {
|
||||||
|
%a = fdiv double %x, 3.2
|
||||||
|
%z = select i1 %c, double %a, double %y
|
||||||
|
ret double %z
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
; Hoist floating-point constant-pool loads out of loops.
|
; Hoist floating-point constant-pool loads out of loops.
|
||||||
|
|
||||||
; CHECK: bar:
|
; CHECK: bar:
|
||||||
|
@ -68,9 +87,9 @@ return:
|
||||||
; Codegen should hoist and CSE these constants.
|
; Codegen should hoist and CSE these constants.
|
||||||
|
|
||||||
; CHECK: vv:
|
; CHECK: vv:
|
||||||
; CHECK: LCPI2_0(%rip), %xmm0
|
; CHECK: LCPI3_0(%rip), %xmm0
|
||||||
; CHECK: LCPI2_1(%rip), %xmm1
|
; CHECK: LCPI3_1(%rip), %xmm1
|
||||||
; CHECK: LCPI2_2(%rip), %xmm2
|
; CHECK: LCPI3_2(%rip), %xmm2
|
||||||
; CHECK: align
|
; CHECK: align
|
||||||
; CHECK-NOT: LCPI
|
; CHECK-NOT: LCPI
|
||||||
; CHECK: ret
|
; CHECK: ret
|
||||||
|
|
|
@ -50,9 +50,9 @@ define i32 @f3(i32 %a) {
|
||||||
ret i32 %2
|
ret i32 %2
|
||||||
}
|
}
|
||||||
; CHECK: f3:
|
; CHECK: f3:
|
||||||
; CHECK-NEXT: ashr r1, r0, 32
|
; CHECK-NEXT: ashr r0, r0, 32
|
||||||
|
; CHECK-NEXT: bf r0
|
||||||
; CHECK-NEXT: ldc r0, 10
|
; CHECK-NEXT: ldc r0, 10
|
||||||
; CHECK-NEXT: bt r1
|
|
||||||
; CHECK: ldc r0, 17
|
; CHECK: ldc r0, 17
|
||||||
|
|
||||||
define i32 @f4(i32 %a) {
|
define i32 @f4(i32 %a) {
|
||||||
|
@ -61,9 +61,9 @@ define i32 @f4(i32 %a) {
|
||||||
ret i32 %2
|
ret i32 %2
|
||||||
}
|
}
|
||||||
; CHECK: f4:
|
; CHECK: f4:
|
||||||
; CHECK-NEXT: ashr r1, r0, 32
|
; CHECK-NEXT: ashr r0, r0, 32
|
||||||
|
; CHECK-NEXT: bf r0
|
||||||
; CHECK-NEXT: ldc r0, 17
|
; CHECK-NEXT: ldc r0, 17
|
||||||
; CHECK-NEXT: bt r1
|
|
||||||
; CHECK: ldc r0, 10
|
; CHECK: ldc r0, 10
|
||||||
|
|
||||||
define i32 @f5(i32 %a) {
|
define i32 @f5(i32 %a) {
|
||||||
|
|
Loading…
Reference in New Issue