[llvm] r324252 - [InstCombine] only allow narrow/wide evaluation of values with >1 use if that user is a binop

Sanjay Patel via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 5 09:16:50 PST 2018


Author: spatel
Date: Mon Feb  5 09:16:50 2018
New Revision: 324252

URL: http://llvm.org/viewvc/llvm-project?rev=324252&view=rev
Log:
[InstCombine] only allow narrow/wide evaluation of values with >1 use if that user is a binop

There was a logic hole in D42739 / rL324014 because we're not accounting for select and phi
instructions that might have repeated operands. This is likely a source of an infinite loop.
I haven't manufactured a test case to prove that, but it should be safe to speculatively limit
this transform to binops while we try to create that test.

Modified:
    llvm/trunk/lib/Transforms/InstCombine/InstCombineCasts.cpp

Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineCasts.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineCasts.cpp?rev=324252&r1=324251&r2=324252&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineCasts.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineCasts.cpp Mon Feb  5 09:16:50 2018
@@ -327,12 +327,14 @@ static bool canNotEvaluateInType(Value *
   if (!isa<Instruction>(V))
     return true;
   // We can't extend or shrink something that has multiple uses -- unless those
-  // multiple uses are all in the same instruction -- doing so would require
-  // duplicating the instruction which isn't profitable.
-  if (!V->hasOneUse())
+  // multiple uses are all in the same binop instruction -- doing so would
+  // require duplicating the instruction which isn't profitable.
+  if (!V->hasOneUse()) {
+    if (!match(V->user_back(), m_BinOp()))
+      return true;
     if (any_of(V->users(), [&](User *U) { return U != V->user_back(); }))
       return true;
-
+  }
   return false;
 }
 




More information about the llvm-commits mailing list