if (Value *X = simplifyUnsignedRangeCheck(Op0, Op1, /*IsAnd=*/false))
return X;
- // FIXME: Use m_APInt to allow vector splat matches.
+ // (icmp (add V, C0), C1) | (icmp V, C0)
ICmpInst::Predicate Pred0, Pred1;
- ConstantInt *CI1, *CI2;
+ const APInt *C0, *C1;
Value *V;
- if (!match(Op0, m_ICmp(Pred0, m_Add(m_Value(V), m_ConstantInt(CI1)),
- m_ConstantInt(CI2))))
+ if (!match(Op0, m_ICmp(Pred0, m_Add(m_Value(V), m_APInt(C0)), m_APInt(C1))))
return nullptr;
- if (!match(Op1, m_ICmp(Pred1, m_Specific(V), m_Specific(CI1))))
+ if (!match(Op1, m_ICmp(Pred1, m_Specific(V), m_Value())))
return nullptr;
- Type *ITy = Op0->getType();
-
auto *AddInst = cast<BinaryOperator>(Op0->getOperand(0));
+ if (AddInst->getOperand(1) != Op1->getOperand(1))
+ return nullptr;
+
+ Type *ITy = Op0->getType();
bool isNSW = AddInst->hasNoSignedWrap();
bool isNUW = AddInst->hasNoUnsignedWrap();
- const APInt &CI1V = CI1->getValue();
- const APInt &CI2V = CI2->getValue();
- const APInt Delta = CI2V - CI1V;
- if (CI1V.isStrictlyPositive()) {
+ const APInt Delta = *C1 - *C0;
+ if (C0->isStrictlyPositive()) {
if (Delta == 2) {
if (Pred0 == ICmpInst::ICMP_UGE && Pred1 == ICmpInst::ICMP_SLE)
return getTrue(ITy);
return getTrue(ITy);
}
}
- if (CI1V.getBoolValue() && isNUW) {
+ if (C0->getBoolValue() && isNUW) {
if (Delta == 2)
if (Pred0 == ICmpInst::ICMP_UGE && Pred1 == ICmpInst::ICMP_ULE)
return getTrue(ITy);
ret <2 x i1> %cmp
}
-; FIXME: Vector splats should fold the same way as scalars in the next 6 pairs of tests.
-
define i1 @or_of_icmps0(i32 %b) {
; CHECK-LABEL: @or_of_icmps0(
; CHECK-NEXT: ret i1 true
define <2 x i1> @or_of_icmps0_vec(<2 x i32> %b) {
; CHECK-LABEL: @or_of_icmps0_vec(
-; CHECK-NEXT: [[TMP1:%.*]] = add <2 x i32> %b, <i32 2, i32 2>
-; CHECK-NEXT: [[TMP2:%.*]] = icmp uge <2 x i32> [[TMP1]], <i32 4, i32 4>
-; CHECK-NEXT: [[CMP3:%.*]] = icmp sle <2 x i32> %b, <i32 2, i32 2>
-; CHECK-NEXT: [[CMP:%.*]] = or <2 x i1> [[TMP2]], [[CMP:%.*]]3
-; CHECK-NEXT: ret <2 x i1> [[CMP]]
+; CHECK-NEXT: ret <2 x i1> <i1 true, i1 true>
;
%1 = add <2 x i32> %b, <i32 2, i32 2>
%2 = icmp uge <2 x i32> %1, <i32 4, i32 4>
define <2 x i1> @or_of_icmps1_vec(<2 x i32> %b) {
; CHECK-LABEL: @or_of_icmps1_vec(
-; CHECK-NEXT: [[TMP1:%.*]] = add nsw <2 x i32> %b, <i32 2, i32 2>
-; CHECK-NEXT: [[TMP2:%.*]] = icmp sge <2 x i32> [[TMP1]], <i32 4, i32 4>
-; CHECK-NEXT: [[CMP3:%.*]] = icmp sle <2 x i32> %b, <i32 2, i32 2>
-; CHECK-NEXT: [[CMP:%.*]] = or <2 x i1> [[TMP2]], [[CMP:%.*]]3
-; CHECK-NEXT: ret <2 x i1> [[CMP]]
+; CHECK-NEXT: ret <2 x i1> <i1 true, i1 true>
;
%1 = add nsw <2 x i32> %b, <i32 2, i32 2>
%2 = icmp sge <2 x i32> %1, <i32 4, i32 4>
define <2 x i1> @or_of_icmps2_vec(<2 x i32> %b) {
; CHECK-LABEL: @or_of_icmps2_vec(
-; CHECK-NEXT: [[TMP1:%.*]] = add <2 x i32> %b, <i32 2, i32 2>
-; CHECK-NEXT: [[TMP2:%.*]] = icmp ugt <2 x i32> [[TMP1]], <i32 3, i32 3>
-; CHECK-NEXT: [[CMP3:%.*]] = icmp sle <2 x i32> %b, <i32 2, i32 2>
-; CHECK-NEXT: [[CMP:%.*]] = or <2 x i1> [[TMP2]], [[CMP:%.*]]3
-; CHECK-NEXT: ret <2 x i1> [[CMP]]
+; CHECK-NEXT: ret <2 x i1> <i1 true, i1 true>
;
%1 = add <2 x i32> %b, <i32 2, i32 2>
%2 = icmp ugt <2 x i32> %1, <i32 3, i32 3>
define <2 x i1> @or_of_icmps3_vec(<2 x i32> %b) {
; CHECK-LABEL: @or_of_icmps3_vec(
-; CHECK-NEXT: [[TMP1:%.*]] = add nsw <2 x i32> %b, <i32 2, i32 2>
-; CHECK-NEXT: [[TMP2:%.*]] = icmp sgt <2 x i32> [[TMP1]], <i32 3, i32 3>
-; CHECK-NEXT: [[CMP3:%.*]] = icmp sle <2 x i32> %b, <i32 2, i32 2>
-; CHECK-NEXT: [[CMP:%.*]] = or <2 x i1> [[TMP2]], [[CMP:%.*]]3
-; CHECK-NEXT: ret <2 x i1> [[CMP]]
+; CHECK-NEXT: ret <2 x i1> <i1 true, i1 true>
;
%1 = add nsw <2 x i32> %b, <i32 2, i32 2>
%2 = icmp sgt <2 x i32> %1, <i32 3, i32 3>
define <2 x i1> @or_of_icmps4_vec(<2 x i32> %b) {
; CHECK-LABEL: @or_of_icmps4_vec(
-; CHECK-NEXT: [[TMP1:%.*]] = add nuw <2 x i32> %b, <i32 2, i32 2>
-; CHECK-NEXT: [[TMP2:%.*]] = icmp uge <2 x i32> [[TMP1]], <i32 4, i32 4>
-; CHECK-NEXT: [[CMP3:%.*]] = icmp ule <2 x i32> %b, <i32 2, i32 2>
-; CHECK-NEXT: [[CMP:%.*]] = or <2 x i1> [[TMP2]], [[CMP:%.*]]3
-; CHECK-NEXT: ret <2 x i1> [[CMP]]
+; CHECK-NEXT: ret <2 x i1> <i1 true, i1 true>
;
%1 = add nuw <2 x i32> %b, <i32 2, i32 2>
%2 = icmp uge <2 x i32> %1, <i32 4, i32 4>
define <2 x i1> @or_of_icmps5_vec(<2 x i32> %b) {
; CHECK-LABEL: @or_of_icmps5_vec(
-; CHECK-NEXT: [[TMP1:%.*]] = add nuw <2 x i32> %b, <i32 2, i32 2>
-; CHECK-NEXT: [[TMP2:%.*]] = icmp ugt <2 x i32> [[TMP1]], <i32 3, i32 3>
-; CHECK-NEXT: [[CMP3:%.*]] = icmp ule <2 x i32> %b, <i32 2, i32 2>
-; CHECK-NEXT: [[CMP:%.*]] = or <2 x i1> [[TMP2]], [[CMP:%.*]]3
-; CHECK-NEXT: ret <2 x i1> [[CMP]]
+; CHECK-NEXT: ret <2 x i1> <i1 true, i1 true>
;
%1 = add nuw <2 x i32> %b, <i32 2, i32 2>
%2 = icmp ugt <2 x i32> %1, <i32 3, i32 3>