[PATCH] D81859: [RFC][SimplifyCFG] Allow target to control SpeculateOneExpensiveInst

Yonghong Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 18 11:27:06 PDT 2020


yonghong-song updated this revision to Diff 271778.
yonghong-song retitled this revision from "[RFC BPF] Prevent Speculative Code Motion" to "[RFC][SimplifyCFG] Allow target to control SpeculateOneExpensiveInst".
yonghong-song edited the summary of this revision.
yonghong-song added a comment.

separate BPF changes to another patch (https://reviews.llvm.org/D82112), so this patch can focus on solely the core change.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D81859/new/

https://reviews.llvm.org/D81859

Files:
  llvm/include/llvm/Analysis/TargetTransformInfo.h
  llvm/include/llvm/Analysis/TargetTransformInfoImpl.h
  llvm/lib/Analysis/TargetTransformInfo.cpp
  llvm/lib/Target/BPF/BPFTargetTransformInfo.h
  llvm/lib/Transforms/Utils/SimplifyCFG.cpp


Index: llvm/lib/Transforms/Utils/SimplifyCFG.cpp
===================================================================
--- llvm/lib/Transforms/Utils/SimplifyCFG.cpp
+++ llvm/lib/Transforms/Utils/SimplifyCFG.cpp
@@ -403,8 +403,11 @@
   // or other expensive operation. The speculation of an expensive instruction
   // is expected to be undone in CodeGenPrepare if the speculation has not
   // enabled further IR optimizations.
+  bool AllowSpeculateOneExpensiveInst = SpeculateOneExpensiveInst &&
+      TTI.allowSpeculateOneExpensiveInst();
   if (BudgetRemaining < 0 &&
-      (!SpeculateOneExpensiveInst || !AggressiveInsts.empty() || Depth > 0))
+      (!AllowSpeculateOneExpensiveInst || !AggressiveInsts.empty() ||
+       Depth > 0))
     return false;
 
   // Okay, we can only really hoist these out if their operands do
Index: llvm/lib/Target/BPF/BPFTargetTransformInfo.h
===================================================================
--- llvm/lib/Target/BPF/BPFTargetTransformInfo.h
+++ llvm/lib/Target/BPF/BPFTargetTransformInfo.h
@@ -44,6 +44,8 @@
 
     return INT_MAX;
   }
+
+  bool allowSpeculateOneExpensiveInst() const { return !ST->getHasAdjustOpt(); }
 };
 
 } // end namespace llvm
Index: llvm/lib/Analysis/TargetTransformInfo.cpp
===================================================================
--- llvm/lib/Analysis/TargetTransformInfo.cpp
+++ llvm/lib/Analysis/TargetTransformInfo.cpp
@@ -946,6 +946,10 @@
   return TTIImpl->getGISelRematGlobalCost();
 }
 
+bool TargetTransformInfo::allowSpeculateOneExpensiveInst() const {
+  return TTIImpl->allowSpeculateOneExpensiveInst();
+}
+
 int TargetTransformInfo::getInstructionLatency(const Instruction *I) const {
   return TTIImpl->getInstructionLatency(I);
 }
Index: llvm/include/llvm/Analysis/TargetTransformInfoImpl.h
===================================================================
--- llvm/include/llvm/Analysis/TargetTransformInfoImpl.h
+++ llvm/include/llvm/Analysis/TargetTransformInfoImpl.h
@@ -638,6 +638,8 @@
 
   bool hasActiveVectorLength() const { return false; }
 
+  bool allowSpeculateOneExpensiveInst() const { return true; }
+
 protected:
   // Obtain the minimum required size to hold the value (without the sign)
   // In case of a vector it returns the min required size for one element.
Index: llvm/include/llvm/Analysis/TargetTransformInfo.h
===================================================================
--- llvm/include/llvm/Analysis/TargetTransformInfo.h
+++ llvm/include/llvm/Analysis/TargetTransformInfo.h
@@ -1198,6 +1198,12 @@
   /// Intrinsics") Use of %evl is discouraged when that is not the case.
   bool hasActiveVectorLength() const;
 
+  /// \returns True if the target permits SpeculateOneExpensiveInst in
+  /// SimplifyCFG. Both this and SimplifyCFG commandline option
+  /// SpeculateOneExpensiveInst need to be True for the actual transformation
+  /// taking place.
+  bool allowSpeculateOneExpensiveInst() const;
+
   /// @}
 
   /// @}
@@ -1465,6 +1471,7 @@
   virtual bool shouldExpandReduction(const IntrinsicInst *II) const = 0;
   virtual unsigned getGISelRematGlobalCost() const = 0;
   virtual bool hasActiveVectorLength() const = 0;
+  virtual bool allowSpeculateOneExpensiveInst() const = 0;
   virtual int getInstructionLatency(const Instruction *I) = 0;
 };
 
@@ -1949,6 +1956,10 @@
     return Impl.hasActiveVectorLength();
   }
 
+  bool allowSpeculateOneExpensiveInst() const override {
+    return Impl.allowSpeculateOneExpensiveInst();
+  }
+
   int getInstructionLatency(const Instruction *I) override {
     return Impl.getInstructionLatency(I);
   }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D81859.271778.patch
Type: text/x-patch
Size: 3602 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200618/3c54fc38/attachment.bin>


More information about the llvm-commits mailing list