@@ -639,6 +639,38 @@ define <2 x i8> @test_vector_ssub_neg_nneg(<2 x i8> %a) {
639
639
640
640
; Raw IR tests
641
641
642
+ define i32 @uadd_sat (i32 %x , i32 %y ) {
643
+ ; CHECK-LABEL: @uadd_sat(
644
+ ; CHECK-NEXT: [[NOTX:%.*]] = xor i32 [[X:%.*]], -1
645
+ ; CHECK-NEXT: [[A:%.*]] = add i32 [[Y:%.*]], [[X]]
646
+ ; CHECK-NEXT: [[C:%.*]] = icmp ult i32 [[NOTX]], [[Y]]
647
+ ; CHECK-NEXT: [[R:%.*]] = select i1 [[C]], i32 -1, i32 [[A]]
648
+ ; CHECK-NEXT: ret i32 [[R]]
649
+ ;
650
+ %notx = xor i32 %x , -1
651
+ %a = add i32 %y , %x
652
+ %c = icmp ult i32 %notx , %y
653
+ %r = select i1 %c , i32 -1 , i32 %a
654
+ ret i32 %r
655
+ }
656
+
657
+ define i32 @uadd_sat_commute1 (i32 %xp , i32 %y ) {
658
+ ; CHECK-LABEL: @uadd_sat_commute1(
659
+ ; CHECK-NEXT: [[X:%.*]] = urem i32 42, [[XP:%.*]]
660
+ ; CHECK-NEXT: [[NOTX:%.*]] = xor i32 [[X]], -1
661
+ ; CHECK-NEXT: [[A:%.*]] = add i32 [[X]], [[Y:%.*]]
662
+ ; CHECK-NEXT: [[C:%.*]] = icmp ult i32 [[NOTX]], [[Y]]
663
+ ; CHECK-NEXT: [[R:%.*]] = select i1 [[C]], i32 -1, i32 [[A]]
664
+ ; CHECK-NEXT: ret i32 [[R]]
665
+ ;
666
+ %x = urem i32 42 , %xp ; thwart complexity-based-canonicalization
667
+ %notx = xor i32 %x , -1
668
+ %a = add i32 %x , %y
669
+ %c = icmp ult i32 %notx , %y
670
+ %r = select i1 %c , i32 -1 , i32 %a
671
+ ret i32 %r
672
+ }
673
+
642
674
define i32 @uadd_sat_constant (i32 %x ) {
643
675
; CHECK-LABEL: @uadd_sat_constant(
644
676
; CHECK-NEXT: [[A:%.*]] = add i32 [[X:%.*]], 42
0 commit comments