CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
211 lines
7.6 KiB
LLVM
211 lines
7.6 KiB
LLVM
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
|
|
; RUN: opt < %s -passes=instcombine -S | FileCheck %s
|
|
|
|
; Optimizes div_ceil idioms:
|
|
; same-type form: add(udiv(X, Y), zext(icmp ne(urem(X, Y), 0)))
|
|
; -> udiv(add nuw(X, Y - 1), Y)
|
|
; zext form: add(zext(udiv(X, Y)), zext(icmp ne(urem(X, Y), 0)))
|
|
; -> zext(udiv(add nuw(X, Y - 1), Y))
|
|
; when X + (Y-1) is provably non-wrapping (via range info on both X and Y).
|
|
|
|
declare void @use(i8)
|
|
declare void @use16(i16)
|
|
|
|
; Variable divisor: both X in [0,100] and Y in [1,10], so max X+(Y-1) = 109 <= 255.
|
|
define i8 @divceil_i8_var_divisor(i8 range(i8 0, 101) %x, i8 range(i8 1, 11) %y) {
|
|
; CHECK-LABEL: @divceil_i8_var_divisor(
|
|
; CHECK-NEXT: [[ROUND:%.*]] = add nsw i8 [[Y:%.*]], -1
|
|
; CHECK-NEXT: [[RESULT1:%.*]] = add nuw i8 [[RESULT:%.*]], [[ROUND]]
|
|
; CHECK-NEXT: [[RESULT2:%.*]] = udiv i8 [[RESULT1]], [[Y]]
|
|
; CHECK-NEXT: ret i8 [[RESULT2]]
|
|
;
|
|
%q = udiv i8 %x, %y
|
|
%r = urem i8 %x, %y
|
|
%cond = icmp ne i8 %r, 0
|
|
%round = zext i1 %cond to i8
|
|
%result = add i8 %q, %round
|
|
ret i8 %result
|
|
}
|
|
|
|
; Variable divisor, commuted add.
|
|
define i8 @divceil_i8_var_divisor_commuted(i8 range(i8 0, 101) %x, i8 range(i8 1, 11) %y) {
|
|
; CHECK-LABEL: @divceil_i8_var_divisor_commuted(
|
|
; CHECK-NEXT: [[ROUND:%.*]] = add nsw i8 [[Y:%.*]], -1
|
|
; CHECK-NEXT: [[RESULT1:%.*]] = add nuw i8 [[RESULT:%.*]], [[ROUND]]
|
|
; CHECK-NEXT: [[RESULT2:%.*]] = udiv i8 [[RESULT1]], [[Y]]
|
|
; CHECK-NEXT: ret i8 [[RESULT2]]
|
|
;
|
|
%q = udiv i8 %x, %y
|
|
%r = urem i8 %x, %y
|
|
%cond = icmp ne i8 %r, 0
|
|
%round = zext i1 %cond to i8
|
|
%result = add i8 %round, %q
|
|
ret i8 %result
|
|
}
|
|
|
|
; Variable divisor with i32: X in [0, 100], Y in [2, 8], max X+(Y-1) = 107 <= UINT32_MAX.
|
|
define i32 @divceil_i32_var_divisor(i32 range(i32 0, 101) %x, i32 range(i32 2, 9) %y) {
|
|
; CHECK-LABEL: @divceil_i32_var_divisor(
|
|
; CHECK-NEXT: [[ROUND:%.*]] = add nsw i32 [[Y:%.*]], -1
|
|
; CHECK-NEXT: [[RESULT1:%.*]] = add nuw nsw i32 [[RESULT:%.*]], [[ROUND]]
|
|
; CHECK-NEXT: [[RESULT2:%.*]] = udiv i32 [[RESULT1]], [[Y]]
|
|
; CHECK-NEXT: ret i32 [[RESULT2]]
|
|
;
|
|
%q = udiv i32 %x, %y
|
|
%r = urem i32 %x, %y
|
|
%cond = icmp ne i32 %r, 0
|
|
%round = zext i1 %cond to i32
|
|
%result = add i32 %q, %round
|
|
ret i32 %result
|
|
}
|
|
|
|
; Negative: Y unbounded -> max Y = 255, max X+(Y-1) = 100+254 overflows i8.
|
|
define i8 @divceil_i8_var_divisor_y_unbounded(i8 range(i8 0, 101) %x, i8 %y) {
|
|
; CHECK-LABEL: @divceil_i8_var_divisor_y_unbounded(
|
|
; CHECK-NEXT: [[Q:%.*]] = udiv i8 [[X:%.*]], [[Y:%.*]]
|
|
; CHECK-NEXT: [[R:%.*]] = urem i8 [[X]], [[Y]]
|
|
; CHECK-NEXT: [[COND:%.*]] = icmp ne i8 [[R]], 0
|
|
; CHECK-NEXT: [[ROUND:%.*]] = zext i1 [[COND]] to i8
|
|
; CHECK-NEXT: [[RESULT:%.*]] = add nuw i8 [[Q]], [[ROUND]]
|
|
; CHECK-NEXT: ret i8 [[RESULT]]
|
|
;
|
|
%q = udiv i8 %x, %y
|
|
%r = urem i8 %x, %y
|
|
%cond = icmp ne i8 %r, 0
|
|
%round = zext i1 %cond to i8
|
|
%result = add i8 %q, %round
|
|
ret i8 %result
|
|
}
|
|
|
|
; Negative: X unbounded -> max X+(Y-1) overflows even with bounded Y.
|
|
define i8 @divceil_i8_var_divisor_x_unbounded(i8 %x, i8 range(i8 1, 11) %y) {
|
|
; CHECK-LABEL: @divceil_i8_var_divisor_x_unbounded(
|
|
; CHECK-NEXT: [[Q:%.*]] = udiv i8 [[X:%.*]], [[Y:%.*]]
|
|
; CHECK-NEXT: [[R:%.*]] = urem i8 [[X]], [[Y]]
|
|
; CHECK-NEXT: [[COND:%.*]] = icmp ne i8 [[R]], 0
|
|
; CHECK-NEXT: [[ROUND:%.*]] = zext i1 [[COND]] to i8
|
|
; CHECK-NEXT: [[RESULT:%.*]] = add i8 [[Q]], [[ROUND]]
|
|
; CHECK-NEXT: ret i8 [[RESULT]]
|
|
;
|
|
%q = udiv i8 %x, %y
|
|
%r = urem i8 %x, %y
|
|
%cond = icmp ne i8 %r, 0
|
|
%round = zext i1 %cond to i8
|
|
%result = add i8 %q, %round
|
|
ret i8 %result
|
|
}
|
|
|
|
; Zext form: udiv/urem in i8, add in i16.
|
|
; X in [0,100], Y in [1,10]: max X+(Y-1) = 109 <= 255.
|
|
define i16 @divceil_i8_var_divisor_zext(i8 range(i8 0, 101) %x, i8 range(i8 1, 11) %y) {
|
|
; CHECK-LABEL: @divceil_i8_var_divisor_zext(
|
|
; CHECK-NEXT: [[TMP1:%.*]] = add nsw i8 [[Y:%.*]], -1
|
|
; CHECK-NEXT: [[TMP2:%.*]] = add nuw i8 [[X:%.*]], [[TMP1]]
|
|
; CHECK-NEXT: [[TMP3:%.*]] = udiv i8 [[TMP2]], [[Y]]
|
|
; CHECK-NEXT: [[RESULT:%.*]] = zext i8 [[TMP3]] to i16
|
|
; CHECK-NEXT: ret i16 [[RESULT]]
|
|
;
|
|
%q = udiv i8 %x, %y
|
|
%r = urem i8 %x, %y
|
|
%cond = icmp ne i8 %r, 0
|
|
%q_ext = zext i8 %q to i16
|
|
%round = zext i1 %cond to i16
|
|
%result = add i16 %q_ext, %round
|
|
ret i16 %result
|
|
}
|
|
|
|
; Zext form, commuted add.
|
|
define i16 @divceil_i8_var_divisor_commuted_zext(i8 range(i8 0, 101) %x, i8 range(i8 1, 11) %y) {
|
|
; CHECK-LABEL: @divceil_i8_var_divisor_commuted_zext(
|
|
; CHECK-NEXT: [[TMP1:%.*]] = add nsw i8 [[Y:%.*]], -1
|
|
; CHECK-NEXT: [[TMP2:%.*]] = add nuw i8 [[X:%.*]], [[TMP1]]
|
|
; CHECK-NEXT: [[TMP3:%.*]] = udiv i8 [[TMP2]], [[Y]]
|
|
; CHECK-NEXT: [[RESULT:%.*]] = zext i8 [[TMP3]] to i16
|
|
; CHECK-NEXT: ret i16 [[RESULT]]
|
|
;
|
|
%q = udiv i8 %x, %y
|
|
%r = urem i8 %x, %y
|
|
%cond = icmp ne i8 %r, 0
|
|
%q_ext = zext i8 %q to i16
|
|
%round = zext i1 %cond to i16
|
|
%result = add i16 %round, %q_ext
|
|
ret i16 %result
|
|
}
|
|
|
|
; Zext form with i16->i32: X in [0, 100], Y in [2, 8].
|
|
define i32 @divceil_i16_var_divisor_zext(i16 range(i16 0, 101) %x, i16 range(i16 2, 9) %y) {
|
|
; CHECK-LABEL: @divceil_i16_var_divisor_zext(
|
|
; CHECK-NEXT: [[TMP1:%.*]] = add nsw i16 [[Y:%.*]], -1
|
|
; CHECK-NEXT: [[TMP2:%.*]] = add nuw nsw i16 [[X:%.*]], [[TMP1]]
|
|
; CHECK-NEXT: [[TMP3:%.*]] = udiv i16 [[TMP2]], [[Y]]
|
|
; CHECK-NEXT: [[RESULT:%.*]] = zext i16 [[TMP3]] to i32
|
|
; CHECK-NEXT: ret i32 [[RESULT]]
|
|
;
|
|
%q = udiv i16 %x, %y
|
|
%r = urem i16 %x, %y
|
|
%cond = icmp ne i16 %r, 0
|
|
%q_ext = zext i16 %q to i32
|
|
%round = zext i1 %cond to i32
|
|
%result = add i32 %q_ext, %round
|
|
ret i32 %result
|
|
}
|
|
|
|
; Zext form negative: Y unbounded -> overflows in i8 type.
|
|
define i16 @divceil_i8_var_divisor_y_unbounded_zext(i8 range(i8 0, 101) %x, i8 %y) {
|
|
; CHECK-LABEL: @divceil_i8_var_divisor_y_unbounded_zext(
|
|
; CHECK-NEXT: [[Q:%.*]] = udiv i8 [[X:%.*]], [[Y:%.*]]
|
|
; CHECK-NEXT: [[R:%.*]] = urem i8 [[X]], [[Y]]
|
|
; CHECK-NEXT: [[COND:%.*]] = icmp ne i8 [[R]], 0
|
|
; CHECK-NEXT: [[Q_EXT:%.*]] = zext nneg i8 [[Q]] to i16
|
|
; CHECK-NEXT: [[ROUND:%.*]] = zext i1 [[COND]] to i16
|
|
; CHECK-NEXT: [[RESULT:%.*]] = add nuw nsw i16 [[Q_EXT]], [[ROUND]]
|
|
; CHECK-NEXT: ret i16 [[RESULT]]
|
|
;
|
|
%q = udiv i8 %x, %y
|
|
%r = urem i8 %x, %y
|
|
%cond = icmp ne i8 %r, 0
|
|
%q_ext = zext i8 %q to i16
|
|
%round = zext i1 %cond to i16
|
|
%result = add i16 %q_ext, %round
|
|
ret i16 %result
|
|
}
|
|
|
|
; Zext form negative: X unbounded -> overflows even with bounded Y.
|
|
define i16 @divceil_i8_var_divisor_x_unbounded_zext(i8 %x, i8 range(i8 1, 11) %y) {
|
|
; CHECK-LABEL: @divceil_i8_var_divisor_x_unbounded_zext(
|
|
; CHECK-NEXT: [[Q:%.*]] = udiv i8 [[X:%.*]], [[Y:%.*]]
|
|
; CHECK-NEXT: [[R:%.*]] = urem i8 [[X]], [[Y]]
|
|
; CHECK-NEXT: [[COND:%.*]] = icmp ne i8 [[R]], 0
|
|
; CHECK-NEXT: [[Q_EXT:%.*]] = zext i8 [[Q]] to i16
|
|
; CHECK-NEXT: [[ROUND:%.*]] = zext i1 [[COND]] to i16
|
|
; CHECK-NEXT: [[RESULT:%.*]] = add nuw nsw i16 [[Q_EXT]], [[ROUND]]
|
|
; CHECK-NEXT: ret i16 [[RESULT]]
|
|
;
|
|
%q = udiv i8 %x, %y
|
|
%r = urem i8 %x, %y
|
|
%cond = icmp ne i8 %r, 0
|
|
%q_ext = zext i8 %q to i16
|
|
%round = zext i1 %cond to i16
|
|
%result = add i16 %q_ext, %round
|
|
ret i16 %result
|
|
}
|
|
|
|
; Trunc form: X comes from trunc nuw of an i32 with range info.
|
|
define i32 @divceil_trunc_nuw_range(i32 range(i32 0, 33) %x_wide) {
|
|
; CHECK-LABEL: @divceil_trunc_nuw_range(
|
|
; CHECK-NEXT: [[X:%.*]] = trunc nuw nsw i32 [[X_WIDE:%.*]] to i8
|
|
; CHECK-NEXT: [[TMP1:%.*]] = add nuw nsw i8 [[X]], 6
|
|
; CHECK-NEXT: [[Q:%.*]] = udiv i8 [[TMP1]], 7
|
|
; CHECK-NEXT: [[Q_EXT:%.*]] = zext nneg i8 [[Q]] to i32
|
|
; CHECK-NEXT: ret i32 [[Q_EXT]]
|
|
;
|
|
%x = trunc nuw i32 %x_wide to i8
|
|
%q = udiv i8 %x, 7
|
|
%r = urem i8 %x, 7
|
|
%cond = icmp ne i8 %r, 0
|
|
%q_ext = zext i8 %q to i32
|
|
%round = zext i1 %cond to i32
|
|
%result = add i32 %q_ext, %round
|
|
ret i32 %result
|
|
}
|