llvm.org GIT mirror llvm / cd00acd
Back-port r276209: ------------------------------------------------------------------------ r276209 | spatel | 2016-07-20 16:40:01 -0700 (Wed, 20 Jul 2016) | 4 lines [InstSimplify][InstCombine] don't crash when folding vector selects of icmp Differential Revision: https://reviews.llvm.org/D22602 ------------------------------------------------------------------------ git-svn-id: https://llvm.org/svn/llvm-project/llvm/branches/release_39@276986 91177308-0d34-0410-b5e6-96231b3b80d8 Hans Wennborg 4 years ago
3 changed file(s) with 31 addition(s) and 2 deletion(s). Raw diff Collapse all Expand all
33993399 return TrueVal;
34003400
34013401 if (const auto *ICI = dyn_cast(CondVal)) {
3402 unsigned BitWidth = Q.DL.getTypeSizeInBits(TrueVal->getType());
3402 // FIXME: This code is nearly duplicated in InstCombine. Using/refactoring
3403 // decomposeBitTestICmp() might help.
3404 unsigned BitWidth =
3405 Q.DL.getTypeSizeInBits(TrueVal->getType()->getScalarType());
34033406 ICmpInst::Predicate Pred = ICI->getPredicate();
34043407 Value *CmpLHS = ICI->getOperand(0);
34053408 Value *CmpRHS = ICI->getOperand(1);
552552 }
553553 }
554554
555 // FIXME: This code is nearly duplicated in InstSimplify. Using/refactoring
556 // decomposeBitTestICmp() might help.
555557 {
556 unsigned BitWidth = DL.getTypeSizeInBits(TrueVal->getType());
558 unsigned BitWidth =
559 DL.getTypeSizeInBits(TrueVal->getType()->getScalarType());
557560 APInt MinSignedValue = APInt::getSignBit(BitWidth);
558561 Value *X;
559562 const APInt *Y, *C;
17361736 %s1 = select i1 %c1, i32 %s0, i32 -1
17371737 ret i32 %s1
17381738 }
1739
1740 define i32 @select_icmp_slt0_xor(i32 %x) {
1741 ; CHECK-LABEL: @select_icmp_slt0_xor(
1742 ; CHECK-NEXT: [[TMP1:%.*]] = or i32 %x, -2147483648
1743 ; CHECK-NEXT: ret i32 [[TMP1]]
1744 ;
1745 %cmp = icmp slt i32 %x, zeroinitializer
1746 %xor = xor i32 %x, 2147483648
1747 %x.xor = select i1 %cmp, i32 %x, i32 %xor
1748 ret i32 %x.xor
1749 }
1750
1751 define <2 x i32> @select_icmp_slt0_xor_vec(<2 x i32> %x) {
1752 ; CHECK-LABEL: @select_icmp_slt0_xor_vec(
1753 ; CHECK-NEXT: [[TMP1:%.*]] = or <2 x i32> %x,
1754 ; CHECK-NEXT: ret <2 x i32> [[TMP1]]
1755 ;
1756 %cmp = icmp slt <2 x i32> %x, zeroinitializer
1757 %xor = xor <2 x i32> %x,
1758 %x.xor = select <2 x i1> %cmp, <2 x i32> %x, <2 x i32> %xor
1759 ret <2 x i32> %x.xor
1760 }
1761