Skip to content

Commit 3e11937

Browse files
committedFeb 17, 2019
[InstCombine] add tests for unsigned saturated add; NFC
We're missing IR canonicalizations for this op as shown in D51929. llvm-svn: 354219
1 parent 0f94326 commit 3e11937

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed
 

‎llvm/test/Transforms/InstCombine/saturating-add-sub.ll

+32
Original file line numberDiff line numberDiff line change
@@ -639,6 +639,38 @@ define <2 x i8> @test_vector_ssub_neg_nneg(<2 x i8> %a) {
639639

640640
; Raw IR tests
641641

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+
642674
define i32 @uadd_sat_constant(i32 %x) {
643675
; CHECK-LABEL: @uadd_sat_constant(
644676
; CHECK-NEXT: [[A:%.*]] = add i32 [[X:%.*]], 42

0 commit comments

Comments
 (0)
Please sign in to comment.