; Raw IR tests
+define i32 @uadd_sat(i32 %x, i32 %y) {
+; CHECK-LABEL: @uadd_sat(
+; CHECK-NEXT: [[NOTX:%.*]] = xor i32 [[X:%.*]], -1
+; CHECK-NEXT: [[A:%.*]] = add i32 [[Y:%.*]], [[X]]
+; CHECK-NEXT: [[C:%.*]] = icmp ult i32 [[NOTX]], [[Y]]
+; CHECK-NEXT: [[R:%.*]] = select i1 [[C]], i32 -1, i32 [[A]]
+; CHECK-NEXT: ret i32 [[R]]
+;
+ %notx = xor i32 %x, -1
+ %a = add i32 %y, %x
+ %c = icmp ult i32 %notx, %y
+ %r = select i1 %c, i32 -1, i32 %a
+ ret i32 %r
+}
+
+define i32 @uadd_sat_commute1(i32 %xp, i32 %y) {
+; CHECK-LABEL: @uadd_sat_commute1(
+; CHECK-NEXT: [[X:%.*]] = urem i32 42, [[XP:%.*]]
+; CHECK-NEXT: [[NOTX:%.*]] = xor i32 [[X]], -1
+; CHECK-NEXT: [[A:%.*]] = add i32 [[X]], [[Y:%.*]]
+; CHECK-NEXT: [[C:%.*]] = icmp ult i32 [[NOTX]], [[Y]]
+; CHECK-NEXT: [[R:%.*]] = select i1 [[C]], i32 -1, i32 [[A]]
+; CHECK-NEXT: ret i32 [[R]]
+;
+ %x = urem i32 42, %xp ; thwart complexity-based-canonicalization
+ %notx = xor i32 %x, -1
+ %a = add i32 %x, %y
+ %c = icmp ult i32 %notx, %y
+ %r = select i1 %c, i32 -1, i32 %a
+ ret i32 %r
+}
+
define i32 @uadd_sat_constant(i32 %x) {
; CHECK-LABEL: @uadd_sat_constant(
; CHECK-NEXT: [[A:%.*]] = add i32 [[X:%.*]], 42