Skip to content
This repository was archived by the owner on Feb 5, 2019. It is now read-only.

Commit cd00acd

Browse files
committed
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
1 parent 2605c1b commit cd00acd

File tree

3 files changed

+31
-2
lines changed

3 files changed

+31
-2
lines changed

lib/Analysis/InstructionSimplify.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3400,7 +3400,10 @@ static Value *SimplifySelectInst(Value *CondVal, Value *TrueVal,
34003400
return TrueVal;
34013401

34023402
if (const auto *ICI = dyn_cast<ICmpInst>(CondVal)) {
3403-
unsigned BitWidth = Q.DL.getTypeSizeInBits(TrueVal->getType());
3403+
// FIXME: This code is nearly duplicated in InstCombine. Using/refactoring
3404+
// decomposeBitTestICmp() might help.
3405+
unsigned BitWidth =
3406+
Q.DL.getTypeSizeInBits(TrueVal->getType()->getScalarType());
34043407
ICmpInst::Predicate Pred = ICI->getPredicate();
34053408
Value *CmpLHS = ICI->getOperand(0);
34063409
Value *CmpRHS = ICI->getOperand(1);

lib/Transforms/InstCombine/InstCombineSelect.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -553,8 +553,11 @@ Instruction *InstCombiner::visitSelectInstWithICmp(SelectInst &SI,
553553
}
554554
}
555555

556+
// FIXME: This code is nearly duplicated in InstSimplify. Using/refactoring
557+
// decomposeBitTestICmp() might help.
556558
{
557-
unsigned BitWidth = DL.getTypeSizeInBits(TrueVal->getType());
559+
unsigned BitWidth =
560+
DL.getTypeSizeInBits(TrueVal->getType()->getScalarType());
558561
APInt MinSignedValue = APInt::getSignBit(BitWidth);
559562
Value *X;
560563
const APInt *Y, *C;

test/Transforms/InstCombine/select.ll

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1737,3 +1737,26 @@ define i32 @PR27137(i32 %a) {
17371737
%s1 = select i1 %c1, i32 %s0, i32 -1
17381738
ret i32 %s1
17391739
}
1740+
1741+
define i32 @select_icmp_slt0_xor(i32 %x) {
1742+
; CHECK-LABEL: @select_icmp_slt0_xor(
1743+
; CHECK-NEXT: [[TMP1:%.*]] = or i32 %x, -2147483648
1744+
; CHECK-NEXT: ret i32 [[TMP1]]
1745+
;
1746+
%cmp = icmp slt i32 %x, zeroinitializer
1747+
%xor = xor i32 %x, 2147483648
1748+
%x.xor = select i1 %cmp, i32 %x, i32 %xor
1749+
ret i32 %x.xor
1750+
}
1751+
1752+
define <2 x i32> @select_icmp_slt0_xor_vec(<2 x i32> %x) {
1753+
; CHECK-LABEL: @select_icmp_slt0_xor_vec(
1754+
; CHECK-NEXT: [[TMP1:%.*]] = or <2 x i32> %x, <i32 -2147483648, i32 -2147483648>
1755+
; CHECK-NEXT: ret <2 x i32> [[TMP1]]
1756+
;
1757+
%cmp = icmp slt <2 x i32> %x, zeroinitializer
1758+
%xor = xor <2 x i32> %x, <i32 2147483648, i32 2147483648>
1759+
%x.xor = select <2 x i1> %cmp, <2 x i32> %x, <2 x i32> %xor
1760+
ret <2 x i32> %x.xor
1761+
}
1762+

0 commit comments

Comments
 (0)