--- /dev/null
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt < %s -instcombine -S | FileCheck %s
+
+; Tests for slt/ult
+
+define i1 @slt_positive_multip_rem_zero(i8 %x) {
+; CHECK-LABEL: @slt_positive_multip_rem_zero(
+; CHECK-NEXT: [[A:%.*]] = mul nsw i8 [[X:%.*]], 7
+; CHECK-NEXT: [[B:%.*]] = icmp slt i8 [[A]], 21
+; CHECK-NEXT: ret i1 [[B]]
+;
+ %a = mul nsw i8 %x, 7
+ %b = icmp slt i8 %a, 21
+ ret i1 %b
+}
+
+define i1 @slt_negative_multip_rem_zero(i8 %x) {
+; CHECK-LABEL: @slt_negative_multip_rem_zero(
+; CHECK-NEXT: [[A:%.*]] = mul nsw i8 [[X:%.*]], -7
+; CHECK-NEXT: [[B:%.*]] = icmp slt i8 [[A]], 21
+; CHECK-NEXT: ret i1 [[B]]
+;
+ %a = mul nsw i8 %x, -7
+ %b = icmp slt i8 %a, 21
+ ret i1 %b
+}
+
+define i1 @slt_positive_multip_rem_nz(i8 %x) {
+; CHECK-LABEL: @slt_positive_multip_rem_nz(
+; CHECK-NEXT: [[A:%.*]] = mul nsw i8 [[X:%.*]], 5
+; CHECK-NEXT: [[B:%.*]] = icmp slt i8 [[A]], 21
+; CHECK-NEXT: ret i1 [[B]]
+;
+ %a = mul nsw i8 %x, 5
+ %b = icmp slt i8 %a, 21
+ ret i1 %b
+}
+
+define i1 @ult_rem_zero(i8 %x) {
+; CHECK-LABEL: @ult_rem_zero(
+; CHECK-NEXT: [[A:%.*]] = mul nuw i8 [[X:%.*]], 7
+; CHECK-NEXT: [[B:%.*]] = icmp ult i8 [[A]], 21
+; CHECK-NEXT: ret i1 [[B]]
+;
+ %a = mul nuw i8 %x, 7
+ %b = icmp ult i8 %a, 21
+ ret i1 %b
+}
+
+define i1 @ult_rem_nz(i8 %x) {
+; CHECK-LABEL: @ult_rem_nz(
+; CHECK-NEXT: [[A:%.*]] = mul nuw i8 [[X:%.*]], 5
+; CHECK-NEXT: [[B:%.*]] = icmp ult i8 [[A]], 21
+; CHECK-NEXT: ret i1 [[B]]
+;
+ %a = mul nuw i8 %x, 5
+ %b = icmp ult i8 %a, 21
+ ret i1 %b
+}
+
+; Tests for sgt/ugt
+
+define i1 @sgt_positive_multip_rem_zero(i8 %x) {
+; CHECK-LABEL: @sgt_positive_multip_rem_zero(
+; CHECK-NEXT: [[A:%.*]] = mul nsw i8 [[X:%.*]], 7
+; CHECK-NEXT: [[B:%.*]] = icmp sgt i8 [[A]], 21
+; CHECK-NEXT: ret i1 [[B]]
+;
+ %a = mul nsw i8 %x, 7
+ %b = icmp sgt i8 %a, 21
+ ret i1 %b
+}
+
+define i1 @sgt_negative_multip_rem_zero(i8 %x) {
+; CHECK-LABEL: @sgt_negative_multip_rem_zero(
+; CHECK-NEXT: [[A:%.*]] = mul nsw i8 [[X:%.*]], -7
+; CHECK-NEXT: [[B:%.*]] = icmp sgt i8 [[A]], 21
+; CHECK-NEXT: ret i1 [[B]]
+;
+ %a = mul nsw i8 %x, -7
+ %b = icmp sgt i8 %a, 21
+ ret i1 %b
+}
+
+define i1 @sgt_positive_multip_rem_nz(i8 %x) {
+; CHECK-LABEL: @sgt_positive_multip_rem_nz(
+; CHECK-NEXT: [[A:%.*]] = mul nsw i8 [[X:%.*]], 5
+; CHECK-NEXT: [[B:%.*]] = icmp sgt i8 [[A]], 21
+; CHECK-NEXT: ret i1 [[B]]
+;
+ %a = mul nsw i8 %x, 5
+ %b = icmp sgt i8 %a, 21
+ ret i1 %b
+}
+
+define i1 @ugt_rem_zero(i8 %x) {
+; CHECK-LABEL: @ugt_rem_zero(
+; CHECK-NEXT: [[A:%.*]] = mul nuw i8 [[X:%.*]], 7
+; CHECK-NEXT: [[B:%.*]] = icmp ugt i8 [[A]], 21
+; CHECK-NEXT: ret i1 [[B]]
+;
+ %a = mul nuw i8 %x, 7
+ %b = icmp ugt i8 %a, 21
+ ret i1 %b
+}
+
+define i1 @ugt_rem_nz(i8 %x) {
+; CHECK-LABEL: @ugt_rem_nz(
+; CHECK-NEXT: [[A:%.*]] = mul nuw i8 [[X:%.*]], 5
+; CHECK-NEXT: [[B:%.*]] = icmp ugt i8 [[A]], 21
+; CHECK-NEXT: ret i1 [[B]]
+;
+ %a = mul nuw i8 %x, 5
+ %b = icmp ugt i8 %a, 21
+ ret i1 %b
+}
+
+; Tests for eq/ne
+
+define i1 @eq_rem_zero(i8 %x) {
+; CHECK-LABEL: @eq_rem_zero(
+; CHECK-NEXT: [[A:%.*]] = mul nuw i8 [[X:%.*]], 5
+; CHECK-NEXT: [[B:%.*]] = icmp eq i8 [[A]], 20
+; CHECK-NEXT: ret i1 [[B]]
+;
+ %a = mul nuw i8 %x, 5
+ %b = icmp eq i8 %a, 20
+ ret i1 %b
+}
+
+define i1 @ne_rem_zero(i8 %x) {
+; CHECK-LABEL: @ne_rem_zero(
+; CHECK-NEXT: [[A:%.*]] = mul nuw i8 [[X:%.*]], 5
+; CHECK-NEXT: [[B:%.*]] = icmp ne i8 [[A]], 30
+; CHECK-NEXT: ret i1 [[B]]
+;
+ %a = mul nuw i8 %x, 5
+ %b = icmp ne i8 %a, 30
+ ret i1 %b
+}
+
+define i1 @eq_rem_nz(i8 %x) {
+; CHECK-LABEL: @eq_rem_nz(
+; CHECK-NEXT: [[A:%.*]] = mul nuw i8 [[X:%.*]], 5
+; CHECK-NEXT: [[B:%.*]] = icmp eq i8 [[A]], 31
+; CHECK-NEXT: ret i1 [[B]]
+;
+ %a = mul nuw i8 %x, 5
+ %b = icmp eq i8 %a, 31
+ ret i1 %b
+}
+
+define i1 @ne_rem_nz(i8 %x) {
+; CHECK-LABEL: @ne_rem_nz(
+; CHECK-NEXT: [[A:%.*]] = mul nuw i8 [[X:%.*]], 5
+; CHECK-NEXT: [[B:%.*]] = icmp ne i8 [[A]], 31
+; CHECK-NEXT: ret i1 [[B]]
+;
+ %a = mul nuw i8 %x, 5
+ %b = icmp ne i8 %a, 31
+ ret i1 %b
+}
+
+; Negative tests for the icmp mul folds
+
+define i1 @sgt_positive_multip_rem_zero_nonsw(i8 %x) {
+; CHECK-LABEL: @sgt_positive_multip_rem_zero_nonsw(
+; CHECK-NEXT: [[A:%.*]] = mul i8 [[X:%.*]], 7
+; CHECK-NEXT: [[B:%.*]] = icmp sgt i8 [[A]], 21
+; CHECK-NEXT: ret i1 [[B]]
+;
+ %a = mul i8 %x, 7
+ %b = icmp sgt i8 %a, 21
+ ret i1 %b
+}
+
+define i1 @ult_multip_rem_zero_nonsw(i8 %x) {
+; CHECK-LABEL: @ult_multip_rem_zero_nonsw(
+; CHECK-NEXT: [[A:%.*]] = mul i8 [[X:%.*]], 7
+; CHECK-NEXT: [[B:%.*]] = icmp ult i8 [[A]], 21
+; CHECK-NEXT: ret i1 [[B]]
+;
+ %a = mul i8 %x, 7
+ %b = icmp ult i8 %a, 21
+ ret i1 %b
+}
+
+define i1 @ugt_rem_zero_nonuw(i8 %x) {
+; CHECK-LABEL: @ugt_rem_zero_nonuw(
+; CHECK-NEXT: [[A:%.*]] = mul i8 [[X:%.*]], 7
+; CHECK-NEXT: [[B:%.*]] = icmp ugt i8 [[A]], 21
+; CHECK-NEXT: ret i1 [[B]]
+;
+ %a = mul i8 %x, 7
+ %b = icmp ugt i8 %a, 21
+ ret i1 %b
+}
+
+define i1 @sgt_minnum(i8 %x) {
+; CHECK-LABEL: @sgt_minnum(
+; CHECK-NEXT: [[A:%.*]] = mul nsw i8 [[X:%.*]], 7
+; CHECK-NEXT: [[B:%.*]] = icmp ne i8 [[A]], -128
+; CHECK-NEXT: ret i1 [[B]]
+;
+ %a = mul nsw i8 %x, 7
+ %b = icmp sgt i8 %a, -128
+ ret i1 %b
+}
+
+define i1 @ule_bignum(i8 %x) {
+; CHECK-LABEL: @ule_bignum(
+; CHECK-NEXT: [[B:%.*]] = icmp eq i8 [[X:%.*]], 0
+; CHECK-NEXT: ret i1 [[B]]
+;
+ %a = mul i8 %x, 2147483647
+ %b = icmp ule i8 %a, 0
+ ret i1 %b
+}
+
+define i1 @sgt_mulzero(i8 %x) {
+; CHECK-LABEL: @sgt_mulzero(
+; CHECK-NEXT: ret i1 false
+;
+ %a = mul nsw i8 %x, 0
+ %b = icmp sgt i8 %a, 21
+ ret i1 %b
+}
+
+define i1 @eq_rem_zero_nonuw(i8 %x) {
+; CHECK-LABEL: @eq_rem_zero_nonuw(
+; CHECK-NEXT: [[A:%.*]] = mul i8 [[X:%.*]], 5
+; CHECK-NEXT: [[B:%.*]] = icmp eq i8 [[A]], 20
+; CHECK-NEXT: ret i1 [[B]]
+;
+ %a = mul i8 %x, 5
+ %b = icmp eq i8 %a, 20
+ ret i1 %b
+}
+
+define i1 @ne_rem_zero_nonuw(i8 %x) {
+; CHECK-LABEL: @ne_rem_zero_nonuw(
+; CHECK-NEXT: [[A:%.*]] = mul i8 [[X:%.*]], 5
+; CHECK-NEXT: [[B:%.*]] = icmp ne i8 [[A]], 30
+; CHECK-NEXT: ret i1 [[B]]
+;
+ %a = mul i8 %x, 5
+ %b = icmp ne i8 %a, 30
+ ret i1 %b
+}