[InstSimplify] move extract with undef index fold; NFC
authorSanjay Patel <spatel@rotateright.com>
Thu, 24 Jun 2021 17:19:07 +0000 (13:19 -0400)
committerSanjay Patel <spatel@rotateright.com>
Thu, 24 Jun 2021 17:22:10 +0000 (13:22 -0400)
This puts it closer to the other undef query check and
will avoid a potential ordering problem if we allow
folding non-constant-int indexes.

llvm/lib/Analysis/InstructionSimplify.cpp

index 62eeacc..2dbd3e0 100644 (file)
@@ -4536,6 +4536,11 @@ static Value *SimplifyExtractElementInst(Value *Vec, Value *Idx,
       return UndefValue::get(VecVTy->getElementType());
   }
 
+  // An undef extract index can be arbitrarily chosen to be an out-of-range
+  // index value, which would result in the instruction being poison.
+  if (Q.isUndefValue(Idx))
+    return PoisonValue::get(VecVTy->getElementType());
+
   // If extracting a specified index from the vector, see if we can recursively
   // find a previously computed scalar that was inserted into the vector.
   if (auto *IdxC = dyn_cast<ConstantInt>(Idx)) {
@@ -4550,12 +4555,6 @@ static Value *SimplifyExtractElementInst(Value *Vec, Value *Idx,
     if (Value *Elt = findScalarElement(Vec, IdxC->getZExtValue()))
       return Elt;
   }
-
-  // An undef extract index can be arbitrarily chosen to be an out-of-range
-  // index value, which would result in the instruction being poison.
-  if (Q.isUndefValue(Idx))
-    return PoisonValue::get(VecVTy->getElementType());
-
   return nullptr;
 }