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

Commit be64cee

Browse files
committed
[InstCombine] Add constant vector support for X udiv C, where C >= signbit
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@324728 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent f197336 commit be64cee

File tree

3 files changed

+14
-13
lines changed

3 files changed

+14
-13
lines changed

lib/Transforms/InstCombine/InstCombineMulDivRem.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1067,8 +1067,7 @@ static Instruction *foldUDivPow2Cst(Value *Op0, Value *Op1,
10671067
// X udiv C, where C >= signbit
10681068
static Instruction *foldUDivNegCst(Value *Op0, Value *Op1,
10691069
const BinaryOperator &I, InstCombiner &IC) {
1070-
Value *ICI = IC.Builder.CreateICmpULT(Op0, cast<ConstantInt>(Op1));
1071-
1070+
Value *ICI = IC.Builder.CreateICmpULT(Op0, cast<Constant>(Op1));
10721071
return SelectInst::Create(ICI, Constant::getNullValue(I.getType()),
10731072
ConstantInt::get(I.getType(), 1));
10741073
}
@@ -1111,12 +1110,11 @@ static size_t visitUDivOperand(Value *Op0, Value *Op1, const BinaryOperator &I,
11111110
return Actions.size();
11121111
}
11131112

1114-
if (ConstantInt *C = dyn_cast<ConstantInt>(Op1))
1115-
// X udiv C, where C >= signbit
1116-
if (C->getValue().isNegative()) {
1117-
Actions.push_back(UDivFoldAction(foldUDivNegCst, C));
1118-
return Actions.size();
1119-
}
1113+
// X udiv C, where C >= signbit
1114+
if (match(Op1, m_Negative())) {
1115+
Actions.push_back(UDivFoldAction(foldUDivNegCst, Op1));
1116+
return Actions.size();
1117+
}
11201118

11211119
// X udiv (C1 << N), where C1 is "1<<C2" --> X >> (N+C2)
11221120
if (match(Op1, m_Shl(m_Power2(), m_Value())) ||

test/Transforms/InstCombine/udiv_select_to_select_shift.ll

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ define i64 @test(i64 %X, i1 %Cond ) {
2424

2525
define <2 x i32> @PR34856(<2 x i32> %t0, <2 x i32> %t1) {
2626
; CHECK-LABEL: @PR34856(
27-
; CHECK-NEXT: [[DIV1:%.*]] = udiv <2 x i32> [[T1:%.*]], <i32 -7, i32 -7>
27+
; CHECK-NEXT: [[TMP1:%.*]] = icmp ugt <2 x i32> [[T1:%.*]], <i32 -8, i32 -8>
28+
; CHECK-NEXT: [[DIV1:%.*]] = zext <2 x i1> [[TMP1]] to <2 x i32>
2829
; CHECK-NEXT: ret <2 x i32> [[DIV1]]
2930
;
3031
%cmp = icmp eq <2 x i32> %t0, <i32 1, i32 1>

test/Transforms/InstCombine/vector-udiv.ll

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,19 @@ define <4 x i32> @test_v4i32_const_pow2(<4 x i32> %a0) {
2222
; X udiv C, where C >= signbit
2323
define <4 x i32> @test_v4i32_negconstsplat(<4 x i32> %a0) {
2424
; CHECK-LABEL: @test_v4i32_negconstsplat(
25-
; CHECK-NEXT: [[TMP1:%.*]] = udiv <4 x i32> [[A0:%.*]], <i32 -3, i32 -3, i32 -3, i32 -3>
26-
; CHECK-NEXT: ret <4 x i32> [[TMP1]]
25+
; CHECK-NEXT: [[TMP1:%.*]] = icmp ugt <4 x i32> [[A0:%.*]], <i32 -4, i32 -4, i32 -4, i32 -4>
26+
; CHECK-NEXT: [[TMP2:%.*]] = zext <4 x i1> [[TMP1]] to <4 x i32>
27+
; CHECK-NEXT: ret <4 x i32> [[TMP2]]
2728
;
2829
%1 = udiv <4 x i32> %a0, <i32 -3, i32 -3, i32 -3, i32 -3>
2930
ret <4 x i32> %1
3031
}
3132

3233
define <4 x i32> @test_v4i32_negconst(<4 x i32> %a0) {
3334
; CHECK-LABEL: @test_v4i32_negconst(
34-
; CHECK-NEXT: [[TMP1:%.*]] = udiv <4 x i32> [[A0:%.*]], <i32 -3, i32 -5, i32 -7, i32 -9>
35-
; CHECK-NEXT: ret <4 x i32> [[TMP1]]
35+
; CHECK-NEXT: [[TMP1:%.*]] = icmp ugt <4 x i32> [[A0:%.*]], <i32 -4, i32 -6, i32 -8, i32 -10>
36+
; CHECK-NEXT: [[TMP2:%.*]] = zext <4 x i1> [[TMP1]] to <4 x i32>
37+
; CHECK-NEXT: ret <4 x i32> [[TMP2]]
3638
;
3739
%1 = udiv <4 x i32> %a0, <i32 -3, i32 -5, i32 -7, i32 -9>
3840
ret <4 x i32> %1

0 commit comments

Comments
 (0)