[PATCH] D130241: [NFC][GVN] Put phi-translation of 'add' behind a switch

Peter Waller via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 21 03:07:12 PDT 2022


peterwaller-arm created this revision.
peterwaller-arm added reviewers: efriedma, fhahn, paulwalker-arm, david-arm.
Herald added subscribers: hiraditya, kristof.beyls.
Herald added a project: All.
peterwaller-arm requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

The code in this `#if 0` block appears to be a net benefit. Put it
behind a switch defaulting to off to support experimentation and as a
request for comment.

The codegen impact of enabling this that I'm currently persuing is that
it allows PRE to take place more frequently, particularly in loops with
second order recurrences.

Preliminary experimental data:

Across LNT on AArch64, 54 benchmarks are sped up by >1%, and 42 are
regressed by >1%, the geomean (exec_time_enabled / exec_time_disabled)
of these 96 "1% or greater significance" benchmarks is 0.991. For the
full set of 770 benchmarks it's 0.998.

There are two benchmarks which experience a >30% speedup, and the worst
slowdown is ~12%, and for every benchmark with a slowdown there is a
benckmark which is sped up by a greater factor.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D130241

Files:
  llvm/lib/Analysis/PHITransAddr.cpp


Index: llvm/lib/Analysis/PHITransAddr.cpp
===================================================================
--- llvm/lib/Analysis/PHITransAddr.cpp
+++ llvm/lib/Analysis/PHITransAddr.cpp
@@ -21,6 +21,10 @@
 #include "llvm/Support/raw_ostream.h"
 using namespace llvm;
 
+static cl::opt<bool> EnableAddPhiTranslation(
+    "gvn-add-phi-translation", cl::init(false), cl::Hidden,
+    cl::desc("Enable phi-translation of add instructions"));
+
 static bool CanPHITrans(Instruction *Inst) {
   if (isa<PHINode>(Inst) ||
       isa<GetElementPtrInst>(Inst))
@@ -410,14 +414,14 @@
     return Result;
   }
 
-#if 0
-  // FIXME: This code works, but it is unclear that we actually want to insert
-  // a big chain of computation in order to make a value available in a block.
-  // This needs to be evaluated carefully to consider its cost trade offs.
-
   // Handle add with a constant RHS.
-  if (Inst->getOpcode() == Instruction::Add &&
+  if (EnableAddPhiTranslation && Inst->getOpcode() == Instruction::Add &&
       isa<ConstantInt>(Inst->getOperand(1))) {
+
+    // FIXME: This code works, but it is unclear that we actually want to insert
+    // a big chain of computation in order to make a value available in a block.
+    // This needs to be evaluated carefully to consider its cost trade offs.
+
     // PHI translate the LHS.
     Value *OpVal = InsertPHITranslatedSubExpr(Inst->getOperand(0),
                                               CurBB, PredBB, DT, NewInsts);
@@ -431,7 +435,6 @@
     NewInsts.push_back(Res);
     return Res;
   }
-#endif
 
   return nullptr;
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D130241.446411.patch
Type: text/x-patch
Size: 1584 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220721/8e1eca65/attachment.bin>


More information about the llvm-commits mailing list