From: Nadav Rotem Date: Thu, 7 Jun 2012 20:28:57 +0000 (+0000) Subject: Fix a bug in FoldSelectOpOp. Bitcast ops may change the number of vector elements... X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=2f6622c7bf10b07ab1370b3696d334bd91d7091d;p=oota-llvm.git Fix a bug in FoldSelectOpOp. Bitcast ops may change the number of vector elements, which may disagree with the select condition type. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@158166 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Transforms/InstCombine/InstCombineSelect.cpp b/lib/Transforms/InstCombine/InstCombineSelect.cpp index 0ae00ea17a8..eb9945b6817 100644 --- a/lib/Transforms/InstCombine/InstCombineSelect.cpp +++ b/lib/Transforms/InstCombine/InstCombineSelect.cpp @@ -129,6 +129,12 @@ Instruction *InstCombiner::FoldSelectOpOp(SelectInst &SI, Instruction *TI, if (TI->isCast()) { if (TI->getOperand(0)->getType() != FI->getOperand(0)->getType()) return 0; + // The select condition may be a vector. We may only change the operand + // type if the vector width remains the same (and matches the condition). + Type *CondTy = SI.getCondition()->getType(); + if (CondTy->isVectorTy() && CondTy->getVectorNumElements() != + FI->getOperand(0)->getType()->getVectorNumElements()) + return 0; } else { return 0; // unknown unary op. } diff --git a/test/Transforms/InstCombine/2012-6-7-vselect-bitcast.ll b/test/Transforms/InstCombine/2012-6-7-vselect-bitcast.ll new file mode 100644 index 00000000000..cb527f86406 --- /dev/null +++ b/test/Transforms/InstCombine/2012-6-7-vselect-bitcast.ll @@ -0,0 +1,11 @@ +; RUN: opt < %s -instcombine -S | FileCheck %s +; CHECK: bitcast + +define void @foo(<16 x i8> %a, <16 x i8> %b, <4 x i32>* %c) { + %aa = bitcast <16 x i8> %a to <4 x i32> + %bb = bitcast <16 x i8> %b to <4 x i32> + %select_v = select <4 x i1> zeroinitializer, <4 x i32> %aa, <4 x i32> %bb + store <4 x i32> %select_v, <4 x i32>* %c, align 4 + ret void +} +