[llvm] r315130 - [InstCombine] use correct type when propagating constant condition in simplifyDivRemOfSelectWithZeroOp (PR34856)
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Fri Oct 6 16:43:06 PDT 2017
Author: spatel
Date: Fri Oct 6 16:43:06 2017
New Revision: 315130
URL: http://llvm.org/viewvc/llvm-project?rev=315130&view=rev
Log:
[InstCombine] use correct type when propagating constant condition in simplifyDivRemOfSelectWithZeroOp (PR34856)
Modified:
llvm/trunk/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
llvm/trunk/test/Transforms/InstCombine/udiv_select_to_select_shift.ll
Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp?rev=315130&r1=315129&r2=315130&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp Fri Oct 6 16:43:06 2017
@@ -813,7 +813,7 @@ bool InstCombiner::simplifyDivRemOfSelec
// 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::simplifyDivRemOfSelec
*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);
}
}
Modified: llvm/trunk/test/Transforms/InstCombine/udiv_select_to_select_shift.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/udiv_select_to_select_shift.ll?rev=315130&r1=315129&r2=315130&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/udiv_select_to_select_shift.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/udiv_select_to_select_shift.ll Fri Oct 6 16:43:06 2017
@@ -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, <i32 -7, i32 -7>
+; CHECK-NEXT: ret <2 x i32> [[DIV1]]
+;
+ %cmp = icmp eq <2 x i32> %t0, <i32 1, i32 1>
+ %zext = zext <2 x i1> %cmp to <2 x i32>
+ %neg = select <2 x i1> %cmp, <2 x i32> zeroinitializer, <2 x i32> <i32 -7, i32 -7>
+ %div1 = udiv <2 x i32> %t1, %neg
+ %use_cmp_again = add <2 x i32> %div1, %zext
+ ret <2 x i32> %use_cmp_again
+}
+
More information about the llvm-commits
mailing list