[llvm-commits] [llvm] r51471 - in /llvm/trunk: lib/Transforms/Scalar/InstructionCombining.cpp test/Transforms/InstCombine/2008-05-22-IDivVector.ll
Nick Lewycky
nicholas at mxc.ca
Thu May 22 20:26:49 PDT 2008
Author: nicholas
Date: Thu May 22 22:26:47 2008
New Revision: 51471
URL: http://llvm.org/viewvc/llvm-project?rev=51471&view=rev
Log:
Fix a recently added optimization to not crash on vectors.
Added:
llvm/trunk/test/Transforms/InstCombine/2008-05-22-IDivVector.ll
Modified:
llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp
Modified: llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp?rev=51471&r1=51470&r2=51471&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp Thu May 22 22:26:47 2008
@@ -3276,8 +3276,16 @@
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;
Added: llvm/trunk/test/Transforms/InstCombine/2008-05-22-IDivVector.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/2008-05-22-IDivVector.ll?rev=51471&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/2008-05-22-IDivVector.ll (added)
+++ llvm/trunk/test/Transforms/InstCombine/2008-05-22-IDivVector.ll Thu May 22 22:26:47 2008
@@ -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
+}
More information about the llvm-commits
mailing list