OSDN Git Service

[SimplifyCFG] allow speculation of exactly one expensive instruction (PR24818)
authorSanjay Patel <spatel@rotateright.com>
Tue, 15 Dec 2015 17:38:29 +0000 (17:38 +0000)
committerSanjay Patel <spatel@rotateright.com>
Tue, 15 Dec 2015 17:38:29 +0000 (17:38 +0000)
commit0c9d12d0d3551bc961e13ad3e8f8954afbaf9265
tree97b681e5564581ca6e215773fb11da62fc168810
parent824c3eccffcd018f624bda8224c5aa946253a163
[SimplifyCFG] allow speculation of exactly one expensive instruction (PR24818)

This is the last general step to allow more IR-level speculation with a safety harness in place in CodeGenPrepare.

The intent is to restore the behavior enabled by:
http://reviews.llvm.org/rL228826

but prevent bad performance such as:
https://llvm.org/bugs/show_bug.cgi?id=24818

Earlier patches in this sequence:
D12882 (disable SimplifyCFG speculation for expensive instructions)
D13297 (have CGP despeculate expensive ops)
D14630 (have CGP despeculate special versions of cttz/ctlz)

As shown in the test cases, we only have two instructions currently affected: ctz for some x86 and fdiv generally.
Allowing exactly one expensive instruction is a bit of a hack, but it lines up with what is currently implemented
in CGP. If we make the despeculation more general in CGP, we can make the speculation here more liberal.

A follow-up patch will adjust the cost for sqrt and possibly other typically expensive math intrinsics (currently
everything is cheap by default). GPU targets would likely want to override those expensive default costs (just as
they probably should already override the cost of div/rem) because just about any math is cheaper than control-flow
on those targets.

Differential Revision: http://reviews.llvm.org/D15213

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@255660 91177308-0d34-0410-b5e6-96231b3b80d8
lib/Transforms/Utils/SimplifyCFG.cpp
test/Transforms/SimplifyCFG/X86/speculate-cttz-ctlz.ll
test/Transforms/SimplifyCFG/speculate-math.ll