[llvm] r178208 - Check if Type is a vector before calling function Type::getVectorNumElements.
Akira Hatanaka
ahatanaka at mips.com
Wed Mar 27 18:28:03 PDT 2013
Author: ahatanak
Date: Wed Mar 27 20:28:02 2013
New Revision: 178208
URL: http://llvm.org/viewvc/llvm-project?rev=178208&view=rev
Log:
Check if Type is a vector before calling function Type::getVectorNumElements.
Added:
llvm/trunk/test/Transforms/InstCombine/vector-type.ll
Modified:
llvm/trunk/lib/Transforms/InstCombine/InstCombineSelect.cpp
Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineSelect.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineSelect.cpp?rev=178208&r1=178207&r2=178208&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineSelect.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineSelect.cpp Wed Mar 27 20:28:02 2013
@@ -127,13 +127,14 @@ Instruction *InstCombiner::FoldSelectOpO
// If this is a non-volatile load or a cast from the same type,
// merge.
if (TI->isCast()) {
- if (TI->getOperand(0)->getType() != FI->getOperand(0)->getType())
+ Type *FIOpndTy = FI->getOperand(0)->getType();
+ if (TI->getOperand(0)->getType() != FIOpndTy)
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())
+ if (CondTy->isVectorTy() && (!FIOpndTy->isVectorTy() ||
+ CondTy->getVectorNumElements() != FIOpndTy->getVectorNumElements()))
return 0;
} else {
return 0; // unknown unary op.
Added: llvm/trunk/test/Transforms/InstCombine/vector-type.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/vector-type.ll?rev=178208&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/vector-type.ll (added)
+++ llvm/trunk/test/Transforms/InstCombine/vector-type.ll Wed Mar 27 20:28:02 2013
@@ -0,0 +1,15 @@
+; The code in InstCombiner::FoldSelectOpOp was calling
+; Type::getVectorNumElements without checking first if the type was a vector.
+
+; RUN: opt < %s -instcombine -S -O3
+
+define i32 @vselect1(i32 %a.coerce, i32 %b.coerce, i32 %c.coerce) {
+entry:
+ %0 = bitcast i32 %a.coerce to <2 x i16>
+ %1 = bitcast i32 %b.coerce to <2 x i16>
+ %2 = bitcast i32 %c.coerce to <2 x i16>
+ %cmp = icmp sge <2 x i16> %2, zeroinitializer
+ %or = select <2 x i1> %cmp, <2 x i16> %0, <2 x i16> %1
+ %3 = bitcast <2 x i16> %or to i32
+ ret i32 %3
+}
More information about the llvm-commits
mailing list