} 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());
}
}
--- /dev/null
+; 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
+}
+