[PATCH] D36552: [LVI] Fix LVI compile time regression around constantFoldUser()

Hiroshi Yamauchi via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 9 14:46:29 PDT 2017

yamauchi updated this revision to Diff 110484.
yamauchi added a comment.

Cleaned up.



Index: lib/Analysis/LazyValueInfo.cpp
--- lib/Analysis/LazyValueInfo.cpp
+++ lib/Analysis/LazyValueInfo.cpp
@@ -1401,6 +1401,14 @@
   return LVILatticeVal::getOverdefined();
+// Return true if the instruction type of Val is supported by
+// constantFoldUser(). Currently CastInst and BinaryOperator only.  Call this
+// before calling constantFoldUser() to find out if it's even worth attempting
+// to call it.
+static bool canConstantFoldUser(Value *Val) {
+  return isa<CastInst>(Val) || isa<BinaryOperator>(Val);
 /// \brief Compute the value of Val on the edge BBFrom -> BBTo. Returns false if
 /// Val is not constrained on the edge.  Result is unspecified if return value
 /// is false.
@@ -1434,7 +1442,9 @@
       if (User *Usr = dyn_cast<User>(Val)) {
         assert(Result.isOverdefined() && "Result isn't overdefined");
-        if (isa<IntegerType>(Val->getType())) {
+        // Check with canConstantFoldUser() first to avoid checking the operands
+        // which can be expensive for a large phi, etc.
+        if (isa<IntegerType>(Val->getType()) && canConstantFoldUser(Val)) {
           const DataLayout &DL = BBTo->getModule()->getDataLayout();
           if (usesOperand(Usr, Condition)) {
             // If Val has Condition as an operand and Val can be folded into a

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D36552.110484.patch
Type: text/x-patch
Size: 1374 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170809/e2e7f900/attachment.bin>

More information about the llvm-commits mailing list