From: Sanjay Patel Date: Fri, 6 Oct 2017 23:43:06 +0000 (+0000) Subject: [InstCombine] use correct type when propagating constant condition in simplifyDivRemO... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1b2747a59f6910eafd0641082f1f655a26468cbf;p=llvm [InstCombine] use correct type when propagating constant condition in simplifyDivRemOfSelectWithZeroOp (PR34856) git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@315130 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp b/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp index 4290d8db989..96a5187e1cf 100644 --- a/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp +++ b/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp @@ -813,7 +813,7 @@ bool InstCombiner::simplifyDivRemOfSelectWithZeroOp(BinaryOperator &I) { // Scan the current block backward, looking for other uses of SI. BasicBlock::iterator BBI = I.getIterator(), BBFront = I.getParent()->begin(); - + Type *CondTy = SelectCond->getType(); while (BBI != BBFront) { --BBI; // If we found a call to a function, we can't assume it will return, so @@ -828,7 +828,8 @@ bool InstCombiner::simplifyDivRemOfSelectWithZeroOp(BinaryOperator &I) { *I = SI->getOperand(NonNullOperand); Worklist.Add(&*BBI); } else if (*I == SelectCond) { - *I = Builder.getInt1(NonNullOperand == 1); + *I = NonNullOperand == 1 ? ConstantInt::getTrue(CondTy) + : ConstantInt::getFalse(CondTy); Worklist.Add(&*BBI); } } diff --git a/test/Transforms/InstCombine/udiv_select_to_select_shift.ll b/test/Transforms/InstCombine/udiv_select_to_select_shift.ll index ab4f51ab5b7..18e65f5f739 100644 --- a/test/Transforms/InstCombine/udiv_select_to_select_shift.ll +++ b/test/Transforms/InstCombine/udiv_select_to_select_shift.ll @@ -19,3 +19,19 @@ define i64 @test(i64 %X, i1 %Cond ) { ret i64 %sum } +; https://bugs.llvm.org/show_bug.cgi?id=34856 +; This would assert/crash because we didn't propagate the condition with the correct vector type. + +define <2 x i32> @PR34856(<2 x i32> %t0, <2 x i32> %t1) { +; CHECK-LABEL: @PR34856( +; CHECK-NEXT: [[DIV1:%.*]] = udiv <2 x i32> %t1, +; CHECK-NEXT: ret <2 x i32> [[DIV1]] +; + %cmp = icmp eq <2 x i32> %t0, + %zext = zext <2 x i1> %cmp to <2 x i32> + %neg = select <2 x i1> %cmp, <2 x i32> zeroinitializer, <2 x i32> + %div1 = udiv <2 x i32> %t1, %neg + %use_cmp_again = add <2 x i32> %div1, %zext + ret <2 x i32> %use_cmp_again +} +