Files
llvm-project/llvm/test/CodeGen/SPIRV/pointers/store-to-array-first-element.ll
Jameson Nash 9d5d2eec21 [Mem2Reg] Remove extraneous getAllocatedType() check (#177438)
Replace uses of getAllocatedType() in PromoteMemoryToRegister.cpp with
type tracking from actual loads and stores. This makes the promotion
logic more semantic - it now checks that all loads/stores use a
consistent type rather than requiring them to match the alloca's
declared type.

Changes:
- isAllocaPromotable() now tracks the first load/store type seen and
ensures all subsequent accesses use the same type
- AllocaInfo gains a ValueType field populated during AnalyzeAlloca()
- PromoteMem2Reg tracks AllocaValueTypes alongside other per-alloca info
- PHI nodes and UndefValues are created using the tracked type

This is semantically more permissive - an alloca declared as i64 but
only accessed as i32 is now promotable. This is correct because the
alloca is just a blob of memory; what matters for Mem2Reg is consistent
access patterns.

Test changes:
- asan-stack-safety.ll: Changed loads/stores to volatile to prevent
promotion while preserving ASAN stack safety analysis behavior
- SPIRV pointer tests (array-skips-gep.ll, load-struct.ll,
store-struct.ll, store-to-array-first-element.ll): Added escape calls to
prevent alloca promotion, as these tests verify SPIRV backend handling
of Function-storage-class pointers

Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-27 21:10:48 -05:00

23 lines
866 B
LLVM

; RUN: llc -verify-machineinstrs -O0 -mtriple=spirv-pc-vulkan1.3-compute %s -o - | FileCheck %s
; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv-pc-vulkan1.3-compute %s -o - -filetype=obj | spirv-val %}
; CHECK-DAG: %[[#Int:]] = OpTypeInt 32 0
; CHECK-DAG: %[[#IntPtr:]] = OpTypePointer Function %[[#Int]]
; CHECK-DAG: %[[#Array:]] = OpTypeArray %[[#Int]] %[[#]]
; CHECK-DAG: %[[#ArrayPtr:]] = OpTypePointer Function %[[#Array]]
; CHECK-DAG: %[[#Const:]] = OpConstant %[[#Int]] 123
; CHECK-DAG: %[[#Zero:]] = OpConstant %[[#Int]] 0
; CHECK: %[[#Var:]] = OpVariable %[[#ArrayPtr]] Function
; CHECK: %[[#GEP:]] = OpInBoundsAccessChain %[[#IntPtr]] %[[#Var]] %[[#Zero]]
; CHECK: OpStore %[[#GEP]] %[[#Const]]
define spir_func void @test_array_store() #0 {
entry:
%var = alloca [4 x i32]
store i32 123, ptr %var
ret void
}
attributes #0 = { optnone noinline }