[llvm] e85d2e4 - [InstCombine] prevent infinite loop from conflicting shuffle mask transforms

Sanjay Patel via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 25 09:14:34 PST 2019


Author: Sanjay Patel
Date: 2019-11-25T12:00:41-05:00
New Revision: e85d2e4981b9db98798ce3e15078775eb50be854

URL: https://github.com/llvm/llvm-project/commit/e85d2e4981b9db98798ce3e15078775eb50be854
DIFF: https://github.com/llvm/llvm-project/commit/e85d2e4981b9db98798ce3e15078775eb50be854.diff

LOG: [InstCombine] prevent infinite loop from conflicting shuffle mask transforms

The pattern in question is currently not possible because we
aggressively (wrongly) transform mask elements to undef values
if they choose from an undef operand. That, however, would
change if we tighten our semantics for shuffles as discussed
in D70641. Adding this check gives us the flexibility to make
that change with minimal overhead for current definitions.

Added: 
    

Modified: 
    llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp b/llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
index fd31f524e5ce..1dba3301cc34 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
@@ -1553,9 +1553,11 @@ static Instruction *foldSelectShuffle(ShuffleVectorInst &Shuf,
   if (!Shuf.isSelect())
     return nullptr;
 
-  // Canonicalize to choose from operand 0 first.
+  // Canonicalize to choose from operand 0 first unless operand 1 is undefined.
+  // Commuting undef to operand 0 conflicts with another canonicalization.
   unsigned NumElts = Shuf.getType()->getVectorNumElements();
-  if (Shuf.getMaskValue(0) >= (int)NumElts) {
+  if (!isa<UndefValue>(Shuf.getOperand(1)) &&
+      Shuf.getMaskValue(0) >= (int)NumElts) {
     // TODO: Can we assert that both operands of a shuffle-select are not undef
     // (otherwise, it would have been folded by instsimplify?
     Shuf.commute();


        


More information about the llvm-commits mailing list