[llvm] [InstSimplify] Fix Inconsistent PHI Simplification (PR #113037)

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Sat Oct 19 06:29:43 PDT 2024


================
@@ -5288,6 +5288,54 @@ Value *llvm::simplifyExtractElementInst(Value *Vec, Value *Idx,
   return ::simplifyExtractElementInst(Vec, Idx, Q, RecursionLimit);
 }
 
+static Value *getCommonPHIValue(Value *PreviousCommon, Value *Current,
+                                const SimplifyQuery &Q) {
+  if (!PreviousCommon)
+    return Current;
+
+  if (PreviousCommon == Current)
+    return PreviousCommon;
+
+  Constant *PreviousCommonC, *CurrentC;
+  if (match(PreviousCommon, m_Constant(PreviousCommonC)) &&
+      match(Current, m_Constant(CurrentC))) {
+    auto *VecTy = dyn_cast<FixedVectorType>(PreviousCommonC->getType());
+    if (VecTy) {
+      SmallVector<Constant *> NewCommonC;
+      unsigned NumElts = VecTy->getNumElements();
+      for (unsigned I = 0; I != NumElts; ++I) {
+        Constant *PrevElt = PreviousCommonC->getAggregateElement(I);
+        Constant *CurrElt = CurrentC->getAggregateElement(I);
+        if (!PrevElt || !CurrElt)
+          return nullptr;
----------------
arsenm wrote:

Can these actually fail at this point? 

https://github.com/llvm/llvm-project/pull/113037


More information about the llvm-commits mailing list