In the function InstCombiner::visitExtractElementInst() removed the limitation that...
authorAnat Shemer <anat.shemer@intel.com>
Thu, 18 Apr 2013 19:56:44 +0000 (19:56 +0000)
committerAnat Shemer <anat.shemer@intel.com>
Thu, 18 Apr 2013 19:56:44 +0000 (19:56 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@179786 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/InstCombine/InstCombineVectorOps.cpp
test/Transforms/InstCombine/vec_extract_2elts.ll [new file with mode: 0644]

index d13c2af4727759eb55d9f3ad0a3e5c46014abe16..79e16f13ad049528d83902439a89f2d6776a093e 100644 (file)
@@ -278,10 +278,10 @@ Instruction *InstCombiner::visitExtractElementInst(ExtractElementInst &EI) {
     } else if (CastInst *CI = dyn_cast<CastInst>(I)) {
       // Canonicalize extractelement(cast) -> cast(extractelement)
       // bitcasts can change the number of vector elements and they cost nothing
-      if (CI->hasOneUse() && EI.hasOneUse() &&
-          (CI->getOpcode() != Instruction::BitCast)) {
-        Value *EE = Builder->CreateExtractElement(CI->getOperand(0),
-                                                  EI.getIndexOperand());
+      if (CI->hasOneUse() && (CI->getOpcode() != Instruction::BitCast)) {
+        Value *EE = InsertNewInstWith(
+                 ExtractElementInst::Create(CI->getOperand(0), EI.getIndexOperand()),
+          *CI);
         return CastInst::Create(CI->getOpcode(), EE, EI.getType());
       }
     }
diff --git a/test/Transforms/InstCombine/vec_extract_2elts.ll b/test/Transforms/InstCombine/vec_extract_2elts.ll
new file mode 100644 (file)
index 0000000..5972340
--- /dev/null
@@ -0,0 +1,12 @@
+; RUN: opt < %s -instcombine -S | FileCheck %s
+
+define void @test(<4 x i32> %v, i64 *%r1, i64 *%r2) {
+;CHECK: %1 = extractelement <4 x i32> %v, i32 0
+;CHECK: %2 = zext i32 %1 to i64
+        %1 = zext <4 x i32> %v to <4 x i64>
+        %2 = extractelement <4 x i64> %1, i32 0
+        store i64 %2, i64 *%r1
+        store i64 %2, i64 *%r2
+        ret void
+}
+