[llvm] r200028 - InstCombine: Don't try to use aggregate elements of ConstantExprs.

Benjamin Kramer benny.kra at googlemail.com
Fri Jan 24 11:02:37 PST 2014


Author: d0k
Date: Fri Jan 24 13:02:37 2014
New Revision: 200028

URL: http://llvm.org/viewvc/llvm-project?rev=200028&view=rev
Log:
InstCombine: Don't try to use aggregate elements of ConstantExprs.

PR18600.

Modified:
    llvm/trunk/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
    llvm/trunk/test/Transforms/InstCombine/vec_extract_var_elt.ll

Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineVectorOps.cpp?rev=200028&r1=200027&r2=200028&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineVectorOps.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineVectorOps.cpp Fri Jan 24 13:02:37 2014
@@ -25,11 +25,13 @@ static bool CheapToScalarize(Value *V, b
     if (isConstant) return true;
 
     // If all elts are the same, we can extract it and use any of the values.
-    Constant *Op0 = C->getAggregateElement(0U);
-    for (unsigned i = 1, e = V->getType()->getVectorNumElements(); i != e; ++i)
-      if (C->getAggregateElement(i) != Op0)
-        return false;
-    return true;
+    if (Constant *Op0 = C->getAggregateElement(0U)) {
+      for (unsigned i = 1, e = V->getType()->getVectorNumElements(); i != e;
+           ++i)
+        if (C->getAggregateElement(i) != Op0)
+          return false;
+      return true;
+    }
   }
   Instruction *I = dyn_cast<Instruction>(V);
   if (!I) return false;

Modified: llvm/trunk/test/Transforms/InstCombine/vec_extract_var_elt.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/vec_extract_var_elt.ll?rev=200028&r1=200027&r2=200028&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/vec_extract_var_elt.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/vec_extract_var_elt.ll Fri Jan 24 13:02:37 2014
@@ -16,3 +16,11 @@ define void @test (float %b, <8 x float>
   ret void    
 }
 
+; PR18600
+define i32 @test2(i32 %i) {
+  %e = extractelement <4 x i32> bitcast (<2 x i64> <i64 1, i64 2> to <4 x i32>), i32 %i
+  ret i32 %e
+
+; CHECK-LABEL: @test2
+; CHECK: extractelement
+}





More information about the llvm-commits mailing list