[llvm] InstructionSimplify: simplify a function (NFC) (PR #91853)

Ramkumar Ramachandra via llvm-commits llvm-commits at lists.llvm.org
Sat May 11 05:35:03 PDT 2024


https://github.com/artagnon created https://github.com/llvm/llvm-project/pull/91853

None

>From 4fefadacf8de0dbd6c5619c54a360b417a1924f3 Mon Sep 17 00:00:00 2001
From: Ramkumar Ramachandra <r at artagnon.com>
Date: Sat, 11 May 2024 13:31:16 +0100
Subject: [PATCH] InstructionSimplify: simplify a function (NFC)

---
 llvm/lib/Analysis/InstructionSimplify.cpp | 30 +++++++++++------------
 1 file changed, 15 insertions(+), 15 deletions(-)

diff --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp
index 37a7259a5cd02..a1a2877db333e 100644
--- a/llvm/lib/Analysis/InstructionSimplify.cpp
+++ b/llvm/lib/Analysis/InstructionSimplify.cpp
@@ -5410,10 +5410,22 @@ static Value *simplifyShuffleVectorInst(Value *Op0, Value *Op1,
   if (Op0Const && Op1Const)
     return ConstantExpr::getShuffleVector(Op0Const, Op1Const, Mask);
 
+  // A shuffle of a splat is always the splat itself. Legal if the shuffle's
+  // value type is same as the input vectors' type.
+  if (auto *OpShuf = dyn_cast<ShuffleVectorInst>(Op0))
+    if (Q.isUndefValue(Op1) && RetTy == InVecTy &&
+        all_equal(OpShuf->getShuffleMask()))
+      return Op0;
+
+  // All remaining transformation depend on the value of the mask, which is
+  // not known at compile time for scalable vectors.
+  if (Scalable)
+    return nullptr;
+
   // Canonicalization: if only one input vector is constant, it shall be the
   // second one. This transformation depends on the value of the mask which
   // is not known at compile time for scalable vectors
-  if (!Scalable && Op0Const && !Op1Const) {
+  if (Op0Const && !Op1Const) {
     std::swap(Op0, Op1);
     ShuffleVectorInst::commuteShuffleMask(Indices,
                                           InVecEltCount.getKnownMinValue());
@@ -5427,8 +5439,8 @@ static Value *simplifyShuffleVectorInst(Value *Op0, Value *Op1,
   // known at compile time for scalable vectors
   Constant *C;
   ConstantInt *IndexC;
-  if (!Scalable && match(Op0, m_InsertElt(m_Value(), m_Constant(C),
-                                          m_ConstantInt(IndexC)))) {
+  if (match(Op0,
+            m_InsertElt(m_Value(), m_Constant(C), m_ConstantInt(IndexC)))) {
     // Match a splat shuffle mask of the insert index allowing undef elements.
     int InsertIndex = IndexC->getZExtValue();
     if (all_of(Indices, [InsertIndex](int MaskElt) {
@@ -5445,18 +5457,6 @@ static Value *simplifyShuffleVectorInst(Value *Op0, Value *Op1,
     }
   }
 
-  // A shuffle of a splat is always the splat itself. Legal if the shuffle's
-  // value type is same as the input vectors' type.
-  if (auto *OpShuf = dyn_cast<ShuffleVectorInst>(Op0))
-    if (Q.isUndefValue(Op1) && RetTy == InVecTy &&
-        all_equal(OpShuf->getShuffleMask()))
-      return Op0;
-
-  // All remaining transformation depend on the value of the mask, which is
-  // not known at compile time for scalable vectors.
-  if (Scalable)
-    return nullptr;
-
   // Don't fold a shuffle with undef mask elements. This may get folded in a
   // better way using demanded bits or other analysis.
   // TODO: Should we allow this?



More information about the llvm-commits mailing list