Skip to content

Commit 452f439

Browse files
committed
[InstCombine] Precommit tests for #86111
The upcoming patch adds logic to prefer to use constants close to power-of-two in these ashr exact + slt/ult patterns when it has a choice on which constant can be used.
1 parent 8c852ab commit 452f439

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed

llvm/test/Transforms/InstCombine/icmp-shr-lt-gt.ll

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3800,3 +3800,64 @@ define i1 @ashrslt_03_15_exact(i4 %x) {
38003800
ret i1 %c
38013801
}
38023802

3803+
; TODO: The resulting compared constant can be safely replaced with one that
3804+
; is closer to a power of two.
3805+
define i1 @ashr_slt_exact_near_pow2_cmpval(i8 %x) {
3806+
; CHECK-LABEL: @ashr_slt_exact_near_pow2_cmpval(
3807+
; CHECK-NEXT: [[C:%.*]] = icmp slt i8 [[X:%.*]], 10
3808+
; CHECK-NEXT: ret i1 [[C]]
3809+
;
3810+
%s = ashr exact i8 %x, 1
3811+
%c = icmp slt i8 %s, 5
3812+
ret i1 %c
3813+
}
3814+
3815+
define i1 @ashr_ult_exact_near_pow2_cmpval(i8 %x) {
3816+
; CHECK-LABEL: @ashr_ult_exact_near_pow2_cmpval(
3817+
; CHECK-NEXT: [[C:%.*]] = icmp ult i8 [[X:%.*]], 10
3818+
; CHECK-NEXT: ret i1 [[C]]
3819+
;
3820+
%s = ashr exact i8 %x, 1
3821+
%c = icmp ult i8 %s, 5
3822+
ret i1 %c
3823+
}
3824+
3825+
define i1 @negtest_near_pow2_cmpval_ashr_slt_noexact(i8 %x) {
3826+
; CHECK-LABEL: @negtest_near_pow2_cmpval_ashr_slt_noexact(
3827+
; CHECK-NEXT: [[C:%.*]] = icmp slt i8 [[X:%.*]], 10
3828+
; CHECK-NEXT: ret i1 [[C]]
3829+
;
3830+
%s = ashr i8 %x, 1
3831+
%c = icmp slt i8 %s, 5
3832+
ret i1 %c
3833+
}
3834+
3835+
define i1 @negtest_near_pow2_cmpval_ashr_wrong_cmp_pred(i8 %x) {
3836+
; CHECK-LABEL: @negtest_near_pow2_cmpval_ashr_wrong_cmp_pred(
3837+
; CHECK-NEXT: [[C:%.*]] = icmp eq i8 [[X:%.*]], 10
3838+
; CHECK-NEXT: ret i1 [[C]]
3839+
;
3840+
%s = ashr exact i8 %x, 1
3841+
%c = icmp eq i8 %s, 5
3842+
ret i1 %c
3843+
}
3844+
3845+
define i1 @negtest_near_pow2_cmpval_isnt_close_to_pow2(i8 %x) {
3846+
; CHECK-LABEL: @negtest_near_pow2_cmpval_isnt_close_to_pow2(
3847+
; CHECK-NEXT: [[C:%.*]] = icmp slt i8 [[X:%.*]], 12
3848+
; CHECK-NEXT: ret i1 [[C]]
3849+
;
3850+
%s = ashr exact i8 %x, 1
3851+
%c = icmp slt i8 %s, 6
3852+
ret i1 %c
3853+
}
3854+
3855+
define i1 @negtest_near_pow2_cmpval_would_overflow_into_signbit(i8 %x) {
3856+
; CHECK-LABEL: @negtest_near_pow2_cmpval_would_overflow_into_signbit(
3857+
; CHECK-NEXT: [[C:%.*]] = icmp sgt i8 [[X:%.*]], -1
3858+
; CHECK-NEXT: ret i1 [[C]]
3859+
;
3860+
%s = ashr exact i8 %x, 2
3861+
%c = icmp ult i8 %s, 33
3862+
ret i1 %c
3863+
}

0 commit comments

Comments
 (0)