@@ -3440,3 +3440,42 @@ define i1 @val_is_aligend_pred_mismatch(i32 %num) {
34403440 %_0 = icmp sge i32 %num.masked , %num
34413441 ret i1 %_0
34423442}
3443+
3444+ define i1 @icmp_samesign_with_nsw_add (i32 %arg0 ) {
3445+ ; CHECK-LABEL: @icmp_samesign_with_nsw_add(
3446+ ; CHECK-NEXT: entry:
3447+ ; CHECK-NEXT: [[TMP0:%.*]] = add i32 [[ARG0:%.*]], -26
3448+ ; CHECK-NEXT: [[V1:%.*]] = icmp ult i32 [[TMP0]], -8
3449+ ; CHECK-NEXT: ret i1 [[V1]]
3450+ ;
3451+ entry:
3452+ %v0 = add nsw i32 %arg0 , -18
3453+ %v1 = icmp samesign ugt i32 %v0 , 7
3454+ ret i1 %v1
3455+ }
3456+
3457+ ; Shouldn't fire since -124 - 12 causes signed overflow
3458+ define i1 @icmp_samesign_with_nsw_add_no_fire (i8 %arg0 ) {
3459+ ; CHECK-LABEL: @icmp_samesign_with_nsw_add_no_fire(
3460+ ; CHECK-NEXT: entry:
3461+ ; CHECK-NEXT: [[TMP0:%.*]] = add i8 [[ARG0:%.*]], -121
3462+ ; CHECK-NEXT: [[V1:%.*]] = icmp ult i8 [[TMP0]], 123
3463+ ; CHECK-NEXT: ret i1 [[V1]]
3464+ ;
3465+ entry:
3466+ %v0 = add nsw i8 %arg0 , 12
3467+ %v1 = icmp samesign ugt i8 %v0 , -124
3468+ ret i1 %v1
3469+ }
3470+
3471+ define i1 @icmp_with_nuw_add (i32 %arg0 ) {
3472+ ; CHECK-LABEL: @icmp_with_nuw_add(
3473+ ; CHECK-NEXT: entry:
3474+ ; CHECK-NEXT: [[V1:%.*]] = icmp ugt i32 [[ARG0:%.*]], 11
3475+ ; CHECK-NEXT: ret i1 [[V1]]
3476+ ;
3477+ entry:
3478+ %v0 = add nuw i32 %arg0 , 7
3479+ %v1 = icmp ugt i32 %v0 , 18
3480+ ret i1 %v1
3481+ }
0 commit comments