@@ -971,3 +971,61 @@ define i1 @slt_offset_nsw(i8 %a, i8 %c) {
971
971
%ov = icmp slt i8 %t , 42
972
972
ret i1 %ov
973
973
}
974
+
975
+ ; FIXME:
976
+ ; In the following 4 tests, we could push the inc/dec
977
+ ; through the min/max, but we should not break up the
978
+ ; min/max idiom by using different icmp and select
979
+ ; operands.
980
+
981
+ define i32 @increment_max (i32 %x ) {
982
+ ; CHECK-LABEL: @increment_max(
983
+ ; CHECK-NEXT: [[A:%.*]] = add nsw i32 [[X:%.*]], 1
984
+ ; CHECK-NEXT: [[C_INV:%.*]] = icmp slt i32 [[X]], 0
985
+ ; CHECK-NEXT: [[S:%.*]] = select i1 [[C_INV]], i32 0, i32 [[A]]
986
+ ; CHECK-NEXT: ret i32 [[S]]
987
+ ;
988
+ %a = add nsw i32 %x , 1
989
+ %c = icmp sgt i32 %a , 0
990
+ %s = select i1 %c , i32 %a , i32 0
991
+ ret i32 %s
992
+ }
993
+
994
+ define i32 @decrement_max (i32 %x ) {
995
+ ; CHECK-LABEL: @decrement_max(
996
+ ; CHECK-NEXT: [[TMP1:%.*]] = icmp sgt i32 [[X:%.*]], 1
997
+ ; CHECK-NEXT: [[TMP2:%.*]] = select i1 [[TMP1]], i32 [[X]], i32 1
998
+ ; CHECK-NEXT: [[S:%.*]] = add nsw i32 [[TMP2]], -1
999
+ ; CHECK-NEXT: ret i32 [[S]]
1000
+ ;
1001
+ %a = add nsw i32 %x , -1
1002
+ %c = icmp sgt i32 %a , 0
1003
+ %s = select i1 %c , i32 %a , i32 0
1004
+ ret i32 %s
1005
+ }
1006
+
1007
+ define i32 @increment_min (i32 %x ) {
1008
+ ; CHECK-LABEL: @increment_min(
1009
+ ; CHECK-NEXT: [[TMP1:%.*]] = icmp slt i32 [[X:%.*]], -1
1010
+ ; CHECK-NEXT: [[TMP2:%.*]] = select i1 [[TMP1]], i32 [[X]], i32 -1
1011
+ ; CHECK-NEXT: [[S:%.*]] = add nsw i32 [[TMP2]], 1
1012
+ ; CHECK-NEXT: ret i32 [[S]]
1013
+ ;
1014
+ %a = add nsw i32 %x , 1
1015
+ %c = icmp slt i32 %a , 0
1016
+ %s = select i1 %c , i32 %a , i32 0
1017
+ ret i32 %s
1018
+ }
1019
+
1020
+ define i32 @decrement_min (i32 %x ) {
1021
+ ; CHECK-LABEL: @decrement_min(
1022
+ ; CHECK-NEXT: [[A:%.*]] = add nsw i32 [[X:%.*]], -1
1023
+ ; CHECK-NEXT: [[C_INV:%.*]] = icmp sgt i32 [[X]], 0
1024
+ ; CHECK-NEXT: [[S:%.*]] = select i1 [[C_INV]], i32 0, i32 [[A]]
1025
+ ; CHECK-NEXT: ret i32 [[S]]
1026
+ ;
1027
+ %a = add nsw i32 %x , -1
1028
+ %c = icmp slt i32 %a , 0
1029
+ %s = select i1 %c , i32 %a , i32 0
1030
+ ret i32 %s
1031
+ }
0 commit comments