From 86dc3f3739eedc26f2fd1f6ade1633c1fa84bd7d Mon Sep 17 00:00:00 2001 From: Anat Shemer Date: Thu, 18 Apr 2013 19:56:44 +0000 Subject: [PATCH] In the function InstCombiner::visitExtractElementInst() removed the limitation that extract is promoted over a cast only if the cast has only one use. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@179786 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/InstCombine/InstCombineVectorOps.cpp | 8 ++++---- test/Transforms/InstCombine/vec_extract_2elts.ll | 12 ++++++++++++ 2 files changed, 16 insertions(+), 4 deletions(-) create mode 100644 test/Transforms/InstCombine/vec_extract_2elts.ll diff --git a/lib/Transforms/InstCombine/InstCombineVectorOps.cpp b/lib/Transforms/InstCombine/InstCombineVectorOps.cpp index d13c2af4727..79e16f13ad0 100644 --- a/lib/Transforms/InstCombine/InstCombineVectorOps.cpp +++ b/lib/Transforms/InstCombine/InstCombineVectorOps.cpp @@ -278,10 +278,10 @@ Instruction *InstCombiner::visitExtractElementInst(ExtractElementInst &EI) { } else if (CastInst *CI = dyn_cast(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 index 00000000000..5972340d60a --- /dev/null +++ b/test/Transforms/InstCombine/vec_extract_2elts.ll @@ -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 +} + -- 2.34.1