Files
TheRock/compiler/amd-llvm/llvm/test/CodeGen/AArch64/GlobalISel/combine-sub-of-mul-const.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

92 lines
2.6 KiB
LLVM

; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 6
; RUN: llc -mtriple=aarch64-none-eabi -global-isel -verify-machineinstrs %s -o - | FileCheck %s
; (sub a, (mul x, K)) where K is a constant lowers to MADD with -K.
; Basic positive K: madd with -7.
define i32 @sub_of_mul_const_pos_k(i32 %x, i32 %a) {
; CHECK-LABEL: sub_of_mul_const_pos_k:
; CHECK: // %bb.0:
; CHECK-NEXT: sub w8, w0, w0, lsl #3
; CHECK-NEXT: add w0, w1, w8
; CHECK-NEXT: ret
%mul = mul i32 %x, 7
%sub = sub i32 %a, %mul
ret i32 %sub
}
; Negative K: madd with +7.
define i32 @sub_of_mul_const_neg_k(i32 %x, i32 %a) {
; CHECK-LABEL: sub_of_mul_const_neg_k:
; CHECK: // %bb.0:
; CHECK-NEXT: lsl w8, w0, #3
; CHECK-NEXT: sub w8, w8, w0
; CHECK-NEXT: add w0, w1, w8
; CHECK-NEXT: ret
%mul = mul i32 %x, -7
%sub = sub i32 %a, %mul
ret i32 %sub
}
; A = 0: collapses via combine_add_with_zero to mul x, -K.
define i32 @sub_of_mul_const_zero_a(i32 %x) {
; CHECK-LABEL: sub_of_mul_const_zero_a:
; CHECK: // %bb.0:
; CHECK-NEXT: sub w0, w0, w0, lsl #3
; CHECK-NEXT: ret
%mul = mul i32 %x, 7
%sub = sub i32 0, %mul
ret i32 %sub
}
; i64 width.
define i64 @sub_of_mul_const_i64(i64 %x, i64 %a) {
; CHECK-LABEL: sub_of_mul_const_i64:
; CHECK: // %bb.0:
; CHECK-NEXT: sub x8, x0, x0, lsl #3
; CHECK-NEXT: add x0, x1, x8
; CHECK-NEXT: ret
%mul = mul i64 %x, 7
%sub = sub i64 %a, %mul
ret i64 %sub
}
; K is not a constant: bail (msub with the original operand).
define i32 @sub_of_mul_non_const(i32 %x, i32 %y, i32 %a) {
; CHECK-LABEL: sub_of_mul_non_const:
; CHECK: // %bb.0:
; CHECK-NEXT: msub w0, w0, w1, w2
; CHECK-NEXT: ret
%mul = mul i32 %x, %y
%sub = sub i32 %a, %mul
ret i32 %sub
}
; Mul has multiple users: bail (would either duplicate or regress).
define i32 @sub_of_mul_const_multi_use(i32 %x, i32 %a, ptr %p) {
; CHECK-LABEL: sub_of_mul_const_multi_use:
; CHECK: // %bb.0:
; CHECK-NEXT: lsl w8, w0, #3
; CHECK-NEXT: sub w8, w8, w0
; CHECK-NEXT: sub w0, w1, w8
; CHECK-NEXT: str w8, [x2]
; CHECK-NEXT: ret
%mul = mul i32 %x, 7
%sub = sub i32 %a, %mul
store i32 %mul, ptr %p
ret i32 %sub
}
; Vector splat: not handled in this scalar-only first cut.
define <4 x i32> @sub_of_mul_const_vector_splat(<4 x i32> %x, <4 x i32> %a) {
; CHECK-LABEL: sub_of_mul_const_vector_splat:
; CHECK: // %bb.0:
; CHECK-NEXT: movi v2.4s, #7
; CHECK-NEXT: mls v1.4s, v0.4s, v2.4s
; CHECK-NEXT: mov v0.16b, v1.16b
; CHECK-NEXT: ret
%mul = mul <4 x i32> %x, <i32 7, i32 7, i32 7, i32 7>
%sub = sub <4 x i32> %a, %mul
ret <4 x i32> %sub
}