Skip to content

Commit

Permalink
[CodeGenPrepare] Remove load-based heuristic
Browse files Browse the repository at this point in the history
Summary:
Both the hardware and LLVM have changed since 2012.
Now, load-based heuristic don't show big differences any more on OoO cores.

There is no notable regressons and improvements on spec2000/2006. (Cortex-A57, Core i5).

Reviewers: spatel, zansari
    
Differential Revision: http://reviews.llvm.org/D16836

llvm-svn: 261809
  • Loading branch information
junmopark-sec committed Feb 25, 2016
1 parent 0a75082 commit 161dc1c
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 37 deletions.
11 changes: 0 additions & 11 deletions llvm/lib/CodeGen/CodeGenPrepare.cpp
Expand Up @@ -4477,17 +4477,6 @@ static bool isFormingBranchFromSelectProfitable(const TargetTransformInfo *TTI,
if (!Cmp || !Cmp->hasOneUse())
return false;

Value *CmpOp0 = Cmp->getOperand(0);
Value *CmpOp1 = Cmp->getOperand(1);

// Emit "cmov on compare with a memory operand" as a branch to avoid stalls
// on a load from memory. But if the load is used more than once, do not
// change the select to a branch because the load is probably needed
// regardless of whether the branch is taken or not.
if ((isa<LoadInst>(CmpOp0) && CmpOp0->hasOneUse()) ||
(isa<LoadInst>(CmpOp1) && CmpOp1->hasOneUse()))
return true;

// If either operand of the select is expensive and only needed on one side
// of the select, we should form a branch.
if (sinkSelectOperand(TTI, SI->getTrueValue()) ||
Expand Down
5 changes: 3 additions & 2 deletions llvm/test/CodeGen/AArch64/a57-csel.ll
@@ -1,8 +1,9 @@
; RUN: llc -mtriple=aarch64-none-linux-gnu < %s -mcpu=cortex-a57 -aarch64-enable-early-ifcvt=false | FileCheck %s

; Check that the select is expanded into a branch sequence.
; Check that the select isn't expanded into a branch sequence
; when the icmp's first operand %x0 is from load.
define i64 @f(i64 %a, i64 %b, i64* %c, i64 %d, i64 %e) {
; CHECK: cbz
; CHECK: csel
%x0 = load i64, i64* %c
%x1 = icmp eq i64 %x0, 0
%x2 = select i1 %x1, i64 %a, i64 %b
Expand Down
19 changes: 2 additions & 17 deletions llvm/test/CodeGen/X86/cmov-into-branch.ll
@@ -1,16 +1,14 @@
; RUN: llc -march=x86-64 -mcpu=core2 < %s | FileCheck %s

; cmp with single-use load, should not form cmov.
; cmp with single-use load, should not form branch.
define i32 @test1(double %a, double* nocapture %b, i32 %x, i32 %y) {
%load = load double, double* %b, align 8
%cmp = fcmp olt double %load, %a
%cond = select i1 %cmp, i32 %x, i32 %y
ret i32 %cond
; CHECK-LABEL: test1:
; CHECK: ucomisd
; CHECK-NOT: cmov
; CHECK: j
; CHECK-NOT: cmov
; CHECK: cmovbel
}

; Sanity check: no load.
Expand All @@ -23,19 +21,6 @@ define i32 @test2(double %a, double %b, i32 %x, i32 %y) {
; CHECK: cmov
}

; Multiple uses of %a, should not form cmov.
define i32 @test3(i32 %a, i32* nocapture %b, i32 %x) {
%load = load i32, i32* %b, align 4
%cmp = icmp ult i32 %load, %a
%cond = select i1 %cmp, i32 %a, i32 %x
ret i32 %cond
; CHECK-LABEL: test3:
; CHECK: cmpl
; CHECK-NOT: cmov
; CHECK: j
; CHECK-NOT: cmov
}

; Multiple uses of the load.
define i32 @test4(i32 %a, i32* nocapture %b, i32 %x, i32 %y) {
%load = load i32, i32* %b, align 4
Expand Down
9 changes: 2 additions & 7 deletions llvm/test/Transforms/CodeGenPrepare/X86/select.ll
Expand Up @@ -2,8 +2,7 @@

target triple = "x86_64-unknown-unknown"

; Nothing to sink here, but this gets converted to a branch to
; avoid stalling an out-of-order CPU on a predictable branch.
; Nothing to sink and convert here.

define i32 @no_sink(double %a, double* %b, i32 %x, i32 %y) {
entry:
Expand All @@ -15,11 +14,7 @@ entry:
; CHECK-LABEL: @no_sink(
; CHECK: %load = load double, double* %b, align 8
; CHECK: %cmp = fcmp olt double %load, %a
; CHECK: br i1 %cmp, label %select.end, label %select.false
; CHECK: select.false:
; CHECK: br label %select.end
; CHECK: select.end:
; CHECK: %sel = phi i32 [ %x, %entry ], [ %y, %select.false ]
; CHECK: %sel = select i1 %cmp, i32 %x, i32 %y
; CHECK: ret i32 %sel
}

Expand Down

0 comments on commit 161dc1c

Please sign in to comment.