%r = select i1 %c, i32 -1, i32 %a
ret i32 %r
}
+define i32 @uadd_sat_nonstrict(i32 %x, i32 %y) {
+; CHECK-LABEL: @uadd_sat_nonstrict(
+; CHECK-NEXT: [[TMP1:%.*]] = call i32 @llvm.uadd.sat.i32(i32 [[X:%.*]], i32 [[Y:%.*]])
+; CHECK-NEXT: ret i32 [[TMP1]]
+;
+ %notx = xor i32 %x, -1
+ %a = add i32 %y, %x
+ %c = icmp ule i32 %notx, %y
+ %r = select i1 %c, i32 -1, i32 %a
+ ret i32 %r
+}
define i32 @uadd_sat_commute_add(i32 %xp, i32 %y) {
; CHECK-LABEL: @uadd_sat_commute_add(
%r = select i1 %c, i32 -1, i32 %a
ret i32 %r
}
+define i32 @uadd_sat_uge(i32 %x, i32 %yp) {
+; CHECK-LABEL: @uadd_sat_uge(
+; CHECK-NEXT: [[Y:%.*]] = sdiv i32 [[YP:%.*]], 2442
+; CHECK-NEXT: [[TMP1:%.*]] = call i32 @llvm.uadd.sat.i32(i32 [[X:%.*]], i32 [[Y]])
+; CHECK-NEXT: ret i32 [[TMP1]]
+;
+ %y = sdiv i32 %yp, 2442 ; thwart complexity-based-canonicalization
+ %notx = xor i32 %x, -1
+ %a = add i32 %y, %x
+ %c = icmp uge i32 %y, %notx
+ %r = select i1 %c, i32 -1, i32 %a
+ ret i32 %r
+}
define <2 x i32> @uadd_sat_ugt_commute_add(<2 x i32> %xp, <2 x i32> %yp) {
; CHECK-LABEL: @uadd_sat_ugt_commute_add(
ret i32 %r
}
+define i32 @uadd_sat_commute_select_nonstrict(i32 %x, i32 %yp) {
+; CHECK-LABEL: @uadd_sat_commute_select_nonstrict(
+; CHECK-NEXT: [[Y:%.*]] = sdiv i32 [[YP:%.*]], 2442
+; CHECK-NEXT: [[TMP1:%.*]] = call i32 @llvm.uadd.sat.i32(i32 [[X:%.*]], i32 [[Y]])
+; CHECK-NEXT: ret i32 [[TMP1]]
+;
+ %y = sdiv i32 %yp, 2442 ; thwart complexity-based-canonicalization
+ %notx = xor i32 %x, -1
+ %a = add i32 %y, %x
+ %c = icmp ule i32 %y, %notx
+ %r = select i1 %c, i32 %a, i32 -1
+ ret i32 %r
+}
+
define i32 @uadd_sat_commute_select_commute_add(i32 %xp, i32 %yp) {
; CHECK-LABEL: @uadd_sat_commute_select_commute_add(
; CHECK-NEXT: [[X:%.*]] = urem i32 42, [[XP:%.*]]
ret i32 %r
}
+define i32 @uadd_sat_not_nonstrict(i32 %x, i32 %y) {
+; CHECK-LABEL: @uadd_sat_not_nonstrict(
+; CHECK-NEXT: [[NOTX:%.*]] = xor i32 [[X:%.*]], -1
+; CHECK-NEXT: [[TMP1:%.*]] = call i32 @llvm.uadd.sat.i32(i32 [[NOTX]], i32 [[Y:%.*]])
+; CHECK-NEXT: ret i32 [[TMP1]]
+;
+ %notx = xor i32 %x, -1
+ %a = add i32 %notx, %y
+ %c = icmp ule i32 %x, %y
+ %r = select i1 %c, i32 -1, i32 %a
+ ret i32 %r
+}
+
define i32 @uadd_sat_not_commute_add(i32 %xp, i32 %yp) {
; CHECK-LABEL: @uadd_sat_not_commute_add(
; CHECK-NEXT: [[X:%.*]] = srem i32 42, [[XP:%.*]]
ret i32 %r
}
+define i32 @uadd_sat_not_uge(i32 %x, i32 %y) {
+; CHECK-LABEL: @uadd_sat_not_uge(
+; CHECK-NEXT: [[NOTX:%.*]] = xor i32 [[X:%.*]], -1
+; CHECK-NEXT: [[TMP1:%.*]] = call i32 @llvm.uadd.sat.i32(i32 [[NOTX]], i32 [[Y:%.*]])
+; CHECK-NEXT: ret i32 [[TMP1]]
+;
+ %notx = xor i32 %x, -1
+ %a = add i32 %notx, %y
+ %c = icmp uge i32 %y, %x
+ %r = select i1 %c, i32 -1, i32 %a
+ ret i32 %r
+}
+
define <2 x i32> @uadd_sat_not_ugt_commute_add(<2 x i32> %x, <2 x i32> %yp) {
; CHECK-LABEL: @uadd_sat_not_ugt_commute_add(
; CHECK-NEXT: [[Y:%.*]] = sdiv <2 x i32> [[YP:%.*]], <i32 2442, i32 4242>
ret i32 %r
}
+define i32 @uadd_sat_not_commute_select_nonstrict(i32 %x, i32 %y) {
+; CHECK-LABEL: @uadd_sat_not_commute_select_nonstrict(
+; CHECK-NEXT: [[NOTX:%.*]] = xor i32 [[X:%.*]], -1
+; CHECK-NEXT: [[TMP1:%.*]] = call i32 @llvm.uadd.sat.i32(i32 [[NOTX]], i32 [[Y:%.*]])
+; CHECK-NEXT: ret i32 [[TMP1]]
+;
+ %notx = xor i32 %x, -1
+ %a = add i32 %notx, %y
+ %c = icmp ule i32 %y, %x
+ %r = select i1 %c, i32 %a, i32 -1
+ ret i32 %r
+}
+
define i32 @uadd_sat_not_commute_select_commute_add(i32 %x, i32 %yp) {
; CHECK-LABEL: @uadd_sat_not_commute_select_commute_add(
; CHECK-NEXT: [[Y:%.*]] = sdiv i32 42, [[YP:%.*]]
ret i32 %r
}
+define i32 @uadd_sat_not_commute_select_uge_commute_add(i32 %x, i32 %y) {
+; CHECK-LABEL: @uadd_sat_not_commute_select_uge_commute_add(
+; CHECK-NEXT: [[NOTX:%.*]] = xor i32 [[X:%.*]], -1
+; CHECK-NEXT: [[TMP1:%.*]] = call i32 @llvm.uadd.sat.i32(i32 [[NOTX]], i32 [[Y:%.*]])
+; CHECK-NEXT: ret i32 [[TMP1]]
+;
+ %notx = xor i32 %x, -1
+ %a = add i32 %notx, %y
+ %c = icmp uge i32 %x, %y
+ %r = select i1 %c, i32 %a, i32 -1
+ ret i32 %r
+}
+
define i32 @uadd_sat_constant(i32 %x) {
; CHECK-LABEL: @uadd_sat_constant(
; CHECK-NEXT: [[A:%.*]] = add i32 [[X:%.*]], 42
%r = add i32 %s, -42
ret i32 %r
}
+
+define i32 @uadd_sat_via_add(i32 %x, i32 %y) {
+; CHECK-LABEL: @uadd_sat_via_add(
+; CHECK-NEXT: [[TMP1:%.*]] = call i32 @llvm.uadd.sat.i32(i32 [[Y:%.*]], i32 [[X:%.*]])
+; CHECK-NEXT: ret i32 [[TMP1]]
+;
+ %a = add i32 %x, %y
+ %c = icmp ult i32 %a, %y
+ %r = select i1 %c, i32 -1, i32 %a
+ ret i32 %r
+}
+
+define i32 @uadd_sat_via_add_nonstrict(i32 %x, i32 %y) {
+; CHECK-LABEL: @uadd_sat_via_add_nonstrict(
+; CHECK-NEXT: [[TMP1:%.*]] = call i32 @llvm.uadd.sat.i32(i32 [[Y:%.*]], i32 [[X:%.*]])
+; CHECK-NEXT: ret i32 [[TMP1]]
+;
+ %a = add i32 %x, %y
+ %c = icmp ule i32 %a, %y
+ %r = select i1 %c, i32 -1, i32 %a
+ ret i32 %r
+}
+
+define i32 @uadd_sat_via_add_swapped_select(i32 %x, i32 %y) {
+; CHECK-LABEL: @uadd_sat_via_add_swapped_select(
+; CHECK-NEXT: [[TMP1:%.*]] = call i32 @llvm.uadd.sat.i32(i32 [[Y:%.*]], i32 [[X:%.*]])
+; CHECK-NEXT: ret i32 [[TMP1]]
+;
+ %a = add i32 %x, %y
+ %c = icmp uge i32 %a, %y
+ %r = select i1 %c, i32 %a, i32 -1
+ ret i32 %r
+}
+
+define i32 @uadd_sat_via_add_swapped_select_strict(i32 %x, i32 %y) {
+; CHECK-LABEL: @uadd_sat_via_add_swapped_select_strict(
+; CHECK-NEXT: [[TMP1:%.*]] = call i32 @llvm.uadd.sat.i32(i32 [[Y:%.*]], i32 [[X:%.*]])
+; CHECK-NEXT: ret i32 [[TMP1]]
+;
+ %a = add i32 %x, %y
+ %c = icmp ugt i32 %a, %y
+ %r = select i1 %c, i32 %a, i32 -1
+ ret i32 %r
+}
+
+define i32 @uadd_sat_via_add_swapped_cmp(i32 %x, i32 %y) {
+; CHECK-LABEL: @uadd_sat_via_add_swapped_cmp(
+; CHECK-NEXT: [[TMP1:%.*]] = call i32 @llvm.uadd.sat.i32(i32 [[Y:%.*]], i32 [[X:%.*]])
+; CHECK-NEXT: ret i32 [[TMP1]]
+;
+ %a = add i32 %x, %y
+ %c = icmp ugt i32 %y, %a
+ %r = select i1 %c, i32 -1, i32 %a
+ ret i32 %r
+}
+
+define i32 @uadd_sat_via_add_swapped_cmp_nonstrict(i32 %x, i32 %y) {
+; CHECK-LABEL: @uadd_sat_via_add_swapped_cmp_nonstrict(
+; CHECK-NEXT: [[TMP1:%.*]] = call i32 @llvm.uadd.sat.i32(i32 [[Y:%.*]], i32 [[X:%.*]])
+; CHECK-NEXT: ret i32 [[TMP1]]
+;
+ %a = add i32 %x, %y
+ %c = icmp uge i32 %y, %a
+ %r = select i1 %c, i32 -1, i32 %a
+ ret i32 %r
+}
+
+define i32 @uadd_sat_via_add_swapped_cmp_nonstric(i32 %x, i32 %y) {
+; CHECK-LABEL: @uadd_sat_via_add_swapped_cmp_nonstric(
+; CHECK-NEXT: [[TMP1:%.*]] = call i32 @llvm.uadd.sat.i32(i32 [[Y:%.*]], i32 [[X:%.*]])
+; CHECK-NEXT: ret i32 [[TMP1]]
+;
+ %a = add i32 %x, %y
+ %c = icmp ule i32 %y, %a
+ %r = select i1 %c, i32 %a, i32 -1
+ ret i32 %r
+}
+
+define i32 @uadd_sat_via_add_swapped_cmp_select_nonstrict(i32 %x, i32 %y) {
+; CHECK-LABEL: @uadd_sat_via_add_swapped_cmp_select_nonstrict(
+; CHECK-NEXT: [[TMP1:%.*]] = call i32 @llvm.uadd.sat.i32(i32 [[Y:%.*]], i32 [[X:%.*]])
+; CHECK-NEXT: ret i32 [[TMP1]]
+;
+ %a = add i32 %x, %y
+ %c = icmp ult i32 %y, %a
+ %r = select i1 %c, i32 %a, i32 -1
+ ret i32 %r
+}