[CodeGenPrepare] limit formation of overflow intrinsics (PR41129)
This is probably a bigger limitation than necessary, but since we don't have any evidence yet
that this transform led to real-world perf improvements rather than regressions, I'm making a
quick, blunt fix.
In the motivating x86 example from:
https://bugs.llvm.org/show_bug.cgi?id=41129
...and shown in the regression test, we want to avoid an extra instruction in the dominating
block because that could be costly.
The x86 LSR test diff is reversing the changes from D57789. There's no evidence that 1 version
is any better than the other yet.
Differential Revision: https://reviews.llvm.org/D59602
llvm-svn: 356665
diff --git a/llvm/lib/CodeGen/CodeGenPrepare.cpp b/llvm/lib/CodeGen/CodeGenPrepare.cpp
index 85c1dc4..e570e98 100644
--- a/llvm/lib/CodeGen/CodeGenPrepare.cpp
+++ b/llvm/lib/CodeGen/CodeGenPrepare.cpp
@@ -1181,10 +1181,14 @@
if (!MathDominates && !DT.dominates(Cmp, BO))
return false;
- // Check that the insertion doesn't create a value that is live across more
- // than two blocks, so to minimise the increase in register pressure.
BasicBlock *MathBB = BO->getParent(), *CmpBB = Cmp->getParent();
if (MathBB != CmpBB) {
+ // Avoid hoisting an extra op into a dominating block and creating a
+ // potentially longer critical path.
+ if (!MathDominates)
+ return false;
+ // Check that the insertion doesn't create a value that is live across
+ // more than two blocks, so to minimise the increase in register pressure.
BasicBlock *Dominator = MathDominates ? MathBB : CmpBB;
BasicBlock *Dominated = MathDominates ? CmpBB : MathBB;
auto Successors = successors(Dominator);