aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNick Lewycky <nicholas@mxc.ca>2008-05-23 03:26:47 +0000
committerNick Lewycky <nicholas@mxc.ca>2008-05-23 03:26:47 +0000
commit386c013d8ceb4d89dee9a1e1c1b69a16e9815c44 (patch)
treec25c2ef8d9070c18854b1cb392e864668e654779
parent4afc4259d2a6408f4d58be0d54e30e4ed86325c8 (diff)
downloadexternal_llvm-386c013d8ceb4d89dee9a1e1c1b69a16e9815c44.zip
external_llvm-386c013d8ceb4d89dee9a1e1c1b69a16e9815c44.tar.gz
external_llvm-386c013d8ceb4d89dee9a1e1c1b69a16e9815c44.tar.bz2
Fix a recently added optimization to not crash on vectors.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@51471 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Transforms/Scalar/InstructionCombining.cpp12
-rw-r--r--test/Transforms/InstCombine/2008-05-22-IDivVector.ll6
2 files changed, 16 insertions, 2 deletions
diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp
index 13dbc11..a398884 100644
--- a/lib/Transforms/Scalar/InstructionCombining.cpp
+++ b/lib/Transforms/Scalar/InstructionCombining.cpp
@@ -3276,8 +3276,16 @@ Instruction *InstCombiner::commonIDivTransforms(BinaryOperator &I) {
Value *Op0 = I.getOperand(0), *Op1 = I.getOperand(1);
// (sdiv X, X) --> 1 (udiv X, X) --> 1
- if (Op0 == Op1)
- return ReplaceInstUsesWith(I, ConstantInt::get(I.getType(), 1));
+ if (Op0 == Op1) {
+ if (const VectorType *Ty = dyn_cast<VectorType>(I.getType())) {
+ ConstantInt *CI = ConstantInt::get(Ty->getElementType(), 1);
+ std::vector<Constant*> Elts(Ty->getNumElements(), CI);
+ return ReplaceInstUsesWith(I, ConstantVector::get(Elts));
+ }
+
+ ConstantInt *CI = ConstantInt::get(I.getType(), 1);
+ return ReplaceInstUsesWith(I, CI);
+ }
if (Instruction *Common = commonDivTransforms(I))
return Common;
diff --git a/test/Transforms/InstCombine/2008-05-22-IDivVector.ll b/test/Transforms/InstCombine/2008-05-22-IDivVector.ll
new file mode 100644
index 0000000..ad70b65
--- /dev/null
+++ b/test/Transforms/InstCombine/2008-05-22-IDivVector.ll
@@ -0,0 +1,6 @@
+; RUN: llvm-as < %s | opt -instcombine -disable-output
+
+define <3 x i8> @f(<3 x i8> %i) {
+ %A = sdiv <3 x i8> %i, %i
+ ret <3 x i8> %A
+}