Files
TheRock/compiler/amd-llvm/llvm/test/CodeGen/NVPTX/divrem-combine.ll
T
derek.holloway 7502bf64a4
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
Flatten subprojects into a single base monorepo
2026-09-02 16:34:47 -07:00

115 lines
3.3 KiB
LLVM

; RUN: llc -O2 < %s -mtriple=nvptx64 -mcpu=sm_35 | FileCheck %s --check-prefix=O2 --check-prefix=CHECK
; RUN: llc -O0 < %s -mtriple=nvptx64 -mcpu=sm_35 | FileCheck %s --check-prefix=O0 --check-prefix=CHECK
; RUN: %if ptxas %{ llc -O2 < %s -mtriple=nvptx64 -mcpu=sm_35 | %ptxas-verify %}
; RUN: %if ptxas %{ llc -O0 < %s -mtriple=nvptx64 -mcpu=sm_35 | %ptxas-verify %}
; The following IR
;
; quot = n / d
; rem = n % d
;
; should be transformed into
;
; quot = n / d
; rem = n - (n / d) * d
;
; during NVPTX isel, at -O2. At -O0, we should leave it alone.
; CHECK-LABEL: sdiv32(
define void @sdiv32(i32 %n, i32 %d, ptr %quot_ret, ptr %rem_ret) {
; CHECK: div.s32 [[quot:%r[0-9]+]], [[num:%r[0-9]+]], [[den:%r[0-9]+]];
%quot = sdiv i32 %n, %d
; O0: rem.s32
; (This is unfortunately order-sensitive, even though mul is commutative.)
; O2: mul.lo.s32 [[mul:%r[0-9]+]], [[quot]], [[den]];
; O2: sub.s32 [[rem:%r[0-9]+]], [[num]], [[mul]]
%rem = srem i32 %n, %d
; O2: st{{.*}}[[quot]]
store i32 %quot, ptr %quot_ret
; O2: st{{.*}}[[rem]]
store i32 %rem, ptr %rem_ret
ret void
}
; CHECK-LABEL: udiv32(
define void @udiv32(i32 %n, i32 %d, ptr %quot_ret, ptr %rem_ret) {
; CHECK: div.u32 [[quot:%r[0-9]+]], [[num:%r[0-9]+]], [[den:%r[0-9]+]];
%quot = udiv i32 %n, %d
; O0: rem.u32
; Selection DAG doesn't know whether this is signed or unsigned
; multiplication and subtraction, but it doesn't make a difference either
; way.
; O2: mul.lo.{{u|s}}32 [[mul:%r[0-9]+]], [[quot]], [[den]];
; O2: sub.{{u|s}}32 [[rem:%r[0-9]+]], [[num]], [[mul]]
%rem = urem i32 %n, %d
; O2: st{{.*}}[[quot]]
store i32 %quot, ptr %quot_ret
; O2: st{{.*}}[[rem]]
store i32 %rem, ptr %rem_ret
ret void
}
; Check that we don't perform this optimization if one operation is signed and
; the other isn't.
; CHECK-LABEL: mismatched_types1(
define void @mismatched_types1(i32 %n, i32 %d, ptr %quot_ret, ptr %rem_ret) {
; CHECK: div.u32
; CHECK: rem.s32
%quot = udiv i32 %n, %d
%rem = srem i32 %n, %d
store i32 %quot, ptr %quot_ret
store i32 %rem, ptr %rem_ret
ret void
}
; CHECK-LABEL: mismatched_types2(
define void @mismatched_types2(i32 %n, i32 %d, ptr %quot_ret, ptr %rem_ret) {
; CHECK: div.s32
; CHECK: rem.u32
%quot = sdiv i32 %n, %d
%rem = urem i32 %n, %d
store i32 %quot, ptr %quot_ret
store i32 %rem, ptr %rem_ret
ret void
}
; Check that we don't perform this optimization if the inputs to the div don't
; match the inputs to the rem.
; CHECK-LABEL: mismatched_inputs1(
define void @mismatched_inputs1(i32 %n, i32 %d, ptr %quot_ret, ptr %rem_ret) {
; CHECK: div.s32
; CHECK: rem.s32
%quot = sdiv i32 %n, %d
%rem = srem i32 %d, %n
store i32 %quot, ptr %quot_ret
store i32 %rem, ptr %rem_ret
ret void
}
; CHECK-LABEL: mismatched_inputs2(
define void @mismatched_inputs2(i32 %n1, i32 %n2, i32 %d, ptr %quot_ret, ptr %rem_ret) {
; CHECK: div.s32
; CHECK: rem.s32
%quot = sdiv i32 %n1, %d
%rem = srem i32 %n2, %d
store i32 %quot, ptr %quot_ret
store i32 %rem, ptr %rem_ret
ret void
}
; CHECK-LABEL: mismatched_inputs3(
define void @mismatched_inputs3(i32 %n, i32 %d1, i32 %d2, ptr %quot_ret, ptr %rem_ret) {
; CHECK: div.s32
; CHECK: rem.s32
%quot = sdiv i32 %n, %d1
%rem = srem i32 %n, %d2
store i32 %quot, ptr %quot_ret
store i32 %rem, ptr %rem_ret
ret void
}