Skip to content

Commit

Permalink
[InstCombine] add tests to show miscompiled smin/smax; NFC
Browse files Browse the repository at this point in the history
  • Loading branch information
rotateright committed Mar 9, 2022
1 parent 0be6fd4 commit cc8f981
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions llvm/test/Transforms/InstCombine/select-min-max.ll
Expand Up @@ -249,3 +249,51 @@ define i8 @umin_umax(i8 %x) {
%s = select i1 %c, i8 %m, i8 126
ret i8 %s
}

define i8 @not_smax(i8 %i41, i8 %i43) {
; CHECK-LABEL: @not_smax(
; CHECK-NEXT: [[I46:%.*]] = sub nsw i8 [[I41:%.*]], [[I43:%.*]]
; CHECK-NEXT: [[TMP1:%.*]] = call i8 @llvm.smax.i8(i8 [[I46]], i8 0)
; CHECK-NEXT: ret i8 [[TMP1]]
;
%i44 = icmp slt i8 %i41, %i43
%i46 = sub nsw i8 %i41, %i43
%spec.select = select i1 %i44, i8 0, i8 %i46
ret i8 %spec.select
}

define i8 @not_smax_swap(i8 %i41, i8 %i43) {
; CHECK-LABEL: @not_smax_swap(
; CHECK-NEXT: [[I46:%.*]] = sub nsw i8 [[I41:%.*]], [[I43:%.*]]
; CHECK-NEXT: [[TMP1:%.*]] = call i8 @llvm.smax.i8(i8 [[I46]], i8 0)
; CHECK-NEXT: ret i8 [[TMP1]]
;
%i44 = icmp sgt i8 %i41, %i43
%i46 = sub nsw i8 %i41, %i43
%spec.select = select i1 %i44, i8 %i46, i8 0
ret i8 %spec.select
}

define i8 @not_smin(i8 %i41, i8 %i43) {
; CHECK-LABEL: @not_smin(
; CHECK-NEXT: [[I46:%.*]] = sub nsw i8 [[I41:%.*]], [[I43:%.*]]
; CHECK-NEXT: [[TMP1:%.*]] = call i8 @llvm.smin.i8(i8 [[I46]], i8 0)
; CHECK-NEXT: ret i8 [[TMP1]]
;
%i44 = icmp sgt i8 %i41, %i43
%i46 = sub nsw i8 %i41, %i43
%spec.select = select i1 %i44, i8 0, i8 %i46
ret i8 %spec.select
}

define i8 @not_smin_swap(i8 %i41, i8 %i43) {
; CHECK-LABEL: @not_smin_swap(
; CHECK-NEXT: [[I46:%.*]] = sub nsw i8 [[I41:%.*]], [[I43:%.*]]
; CHECK-NEXT: [[TMP1:%.*]] = call i8 @llvm.smin.i8(i8 [[I46]], i8 0)
; CHECK-NEXT: ret i8 [[TMP1]]
;
%i44 = icmp slt i8 %i41, %i43
%i46 = sub nsw i8 %i41, %i43
%spec.select = select i1 %i44, i8 %i46, i8 0
ret i8 %spec.select
}

0 comments on commit cc8f981

Please sign in to comment.