Commit d2ec416c authored by David Green's avatar David Green
Browse files

[InstCombine][NFC] Tests for uadd.sat and sadd.sat canonicalisation.

parent 4c430a7c
Loading
Loading
Loading
Loading
+730 −0

File added.

Preview size limit exceeded, changes collapsed.

+48 −0
Original line number Diff line number Diff line
@@ -1484,6 +1484,54 @@ define i32 @uadd_sat_constant_commute(i32 %x) {
  ret i32 %r
}

define i32 @uadd_sat_canon(i32 %x, i32 %y) {
; CHECK-LABEL: @uadd_sat_canon(
; CHECK-NEXT:    [[A:%.*]] = add i32 [[X:%.*]], [[Y:%.*]]
; CHECK-NEXT:    [[C:%.*]] = icmp ult i32 [[A]], [[X]]
; CHECK-NEXT:    [[R:%.*]] = select i1 [[C]], i32 -1, i32 [[A]]
; CHECK-NEXT:    ret i32 [[R]]
;
  %a = add i32 %x, %y
  %c = icmp ult i32 %a, %x
  %r = select i1 %c, i32 -1, i32 %a
  ret i32 %r
}

define i32 @uadd_sat_canon_y(i32 %x, i32 %y) {
; CHECK-LABEL: @uadd_sat_canon_y(
; CHECK-NEXT:    [[A:%.*]] = add i32 [[X:%.*]], [[Y:%.*]]
; CHECK-NEXT:    [[C:%.*]] = icmp ult i32 [[A]], [[Y]]
; CHECK-NEXT:    [[R:%.*]] = select i1 [[C]], i32 -1, i32 [[A]]
; CHECK-NEXT:    ret i32 [[R]]
;
  %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_canon_nuw(i32 %x, i32 %y) {
; CHECK-LABEL: @uadd_sat_canon_nuw(
; CHECK-NEXT:    [[A:%.*]] = add nuw i32 [[X:%.*]], [[Y:%.*]]
; CHECK-NEXT:    ret i32 [[A]]
;
  %a = add nuw i32 %x, %y
  %c = icmp ult i32 %a, %x
  %r = select i1 %c, i32 -1, i32 %a
  ret i32 %r
}

define i32 @uadd_sat_canon_y_nuw(i32 %x, i32 %y) {
; CHECK-LABEL: @uadd_sat_canon_y_nuw(
; CHECK-NEXT:    [[A:%.*]] = add nuw i32 [[X:%.*]], [[Y:%.*]]
; CHECK-NEXT:    ret i32 [[A]]
;
  %a = add nuw i32 %x, %y
  %c = icmp ult i32 %a, %y
  %r = select i1 %c, i32 -1, i32 %a
  ret i32 %r
}

define <4 x i32> @uadd_sat_constant_vec(<4 x i32> %x) {
; CHECK-LABEL: @uadd_sat_constant_vec(
; CHECK-NEXT:    [[A:%.*]] = add <4 x i32> [[X:%.*]], <i32 42, i32 42, i32 42, i32 42>