Files
TheRock/compiler/amd-llvm/llvm/test/Transforms/GlobalOpt/invariant.group.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

104 lines
2.7 KiB
LLVM

; RUN: opt -S -passes=globalopt < %s | FileCheck %s
; CHECK: @llvm.global_ctors = appending global [1 x {{.*}}@_GLOBAL__I_c
@llvm.global_ctors = appending global [3 x { i32, ptr, ptr }] [{ i32, ptr, ptr } { i32 65535, ptr @_GLOBAL__I_a, ptr null }, { i32, ptr, ptr } { i32 65535, ptr @_GLOBAL__I_b, ptr null }, { i32, ptr, ptr } { i32 65535, ptr @_GLOBAL__I_c, ptr null }]
; CHECK: @tmp = local_unnamed_addr global i32 42
; CHECK: @tmp2 = local_unnamed_addr global i32 42
; CHECK: @tmp3 = global i32 42
@tmp = global i32 0
@tmp2 = global i32 0
@tmp3 = global i32 0
@ptrToTmp3 = global ptr null
define i32 @TheAnswerToLifeTheUniverseAndEverything() {
ret i32 42
}
define void @_GLOBAL__I_a() {
enter:
call void @_optimizable()
call void @_not_optimizable()
ret void
}
define void @_optimizable() {
enter:
%valptr = alloca i32
%val = call i32 @TheAnswerToLifeTheUniverseAndEverything()
store i32 %val, ptr @tmp
store i32 %val, ptr %valptr
%barr = call ptr @llvm.launder.invariant.group(ptr %valptr)
%val2 = load i32, ptr %barr
store i32 %val2, ptr @tmp2
ret void
}
; We can't step through launder.invariant.group here, because that would change
; this load in @usage_of_globals()
; %val = load i32, ptr %ptrVal, !invariant.group !0
; into
; %val = load i32, ptr @tmp3, !invariant.group !0
; and then we could assume that %val and %val2 to be the same, which coud be
; false, because @changeTmp3ValAndCallBarrierInside() may change the value
; of @tmp3.
define void @_not_optimizable() {
enter:
store i32 13, ptr @tmp3, !invariant.group !0
%barr = call ptr @llvm.launder.invariant.group(ptr @tmp3)
store ptr %barr, ptr @ptrToTmp3
store i32 42, ptr %barr, !invariant.group !0
ret void
}
define void @usage_of_globals() {
entry:
%ptrVal = load ptr, ptr @ptrToTmp3
%val = load i32, ptr %ptrVal, !invariant.group !0
call void @changeTmp3ValAndCallBarrierInside()
%val2 = load i32, ptr @tmp3, !invariant.group !0
ret void;
}
@tmp4 = global i32 0
define void @_GLOBAL__I_b() {
enter:
%val = call i32 @TheAnswerToLifeTheUniverseAndEverything()
%p2 = call ptr @llvm.strip.invariant.group.p0(ptr @tmp4)
store i32 %val, ptr %p2
ret void
}
@tmp5 = global i32 0
@tmp6 = global ptr null
; CHECK: @tmp6 = local_unnamed_addr global ptr null
define ptr @_dont_return_param(ptr %p) {
%p2 = call ptr @llvm.launder.invariant.group(ptr %p)
ret ptr %p2
}
; We should bail out if we return any pointers derived via invariant.group intrinsics at any point.
define void @_GLOBAL__I_c() {
enter:
%tmp5 = call ptr @_dont_return_param(ptr @tmp5)
store ptr %tmp5, ptr @tmp6
ret void
}
declare void @changeTmp3ValAndCallBarrierInside()
declare ptr @llvm.launder.invariant.group(ptr)
declare ptr @llvm.strip.invariant.group.p0(ptr)
!0 = !{}