Author: Nathan Corbyn Date: 2026-11-08T15:41:55+01:00 New Revision: 13b0ce2b2cda79e868010913677e024038954b1b
URL: https://github.com/llvm/llvm-project/commit/13b0ce2b2cda79e868010913677e024038954b1b DIFF: https://github.com/llvm/llvm-project/commit/13b0ce2b2cda79e868010913677e024038954b1b.diff LOG: [StackColoring] Update IR when merging stack slots of differing alignment (#237412) (cherry picked from commit 7c3ae84d7f3a14bea27de8eac22cf8f7964ac711) Added: llvm/test/CodeGen/AArch64/stack-coloring-alignment.ll Modified: llvm/lib/CodeGen/StackColoring.cpp Removed: ################################################################################ diff --git a/llvm/lib/CodeGen/StackColoring.cpp b/llvm/lib/CodeGen/StackColoring.cpp index ea1f33f791765a..a036925a62401d 100644 --- a/llvm/lib/CodeGen/StackColoring.cpp +++ b/llvm/lib/CodeGen/StackColoring.cpp @@ -944,6 +944,10 @@ void StackColoring::remapInstructions(DenseMap<int, int> &SlotRemap) { // somehow, is to directly update the IR to reflect the change being made // here. Instruction *Inst = const_cast<AllocaInst *>(To); + // Inherit maximum alignment. + if (From->getAlign() > To->getAlign()) + cast<AllocaInst>(Inst)->setAlignment(From->getAlign()); + // Fix-up types. if (From->getType() != To->getType()) { BitCastInst *Cast = new BitCastInst(Inst, From->getType()); Cast->insertAfter(Inst->getIterator()); diff --git a/llvm/test/CodeGen/AArch64/stack-coloring-alignment.ll b/llvm/test/CodeGen/AArch64/stack-coloring-alignment.ll new file mode 100644 index 00000000000000..951fa193e341ce --- /dev/null +++ b/llvm/test/CodeGen/AArch64/stack-coloring-alignment.ll @@ -0,0 +1,33 @@ +; RUN: llc -filetype=null %s -mtriple=arm64-apple-darwin -misched-print-dags 2>&1 | FileCheck %s +; REQUIRES: asserts + +; Test that stack coloring merging allocas of diff ering alignments does not +; corrupt BasicAA results. + +define <3 x float> @test_stack_coloring_maintains_alignment_metadata() { + ; CHECK-LABEL: test_stack_coloring_maintains_alignment_metadata:%bb.0 + ; CHECK: SU(0): STRWui $wzr, %stack.0.alloca.a, 1 :: (store (s32) into %ir.alloca.b.1) + ; CHECK: Successors: + ; CHECK-NEXT: SU(1): Ord Latency=1 Memory + ; CHECK: SU(1): %2:fpr128 = LDRQui %stack.0.alloca.a, 0 :: (dereferenceable load (s128) from %ir.alloca.a) + ; CHECK: Successors: + ; CHECK-NEXT: SU(2): Data Latency=2 Reg=%2 + %alloca.a = alloca [3 x float], align 4 + %alloca.b = alloca [3 x float], align 16 + + call void @llvm.lifetime.start.p0(ptr %alloca.a) + call void @escape(ptr %alloca.a) + call void @llvm.lifetime.end.p0(ptr %alloca.a) + + call void @llvm.lifetime.start.p0(ptr %alloca.b) + %alloca.b.1 = getelementptr i8, ptr %alloca.b, i64 4 + ; After merging stack slots, the following store must not be reordered past + ; the subsequent load. + store float 0., ptr %alloca.b.1 + %v = load <3 x float>, ptr %alloca.b, align 16 + call void @llvm.lifetime.end.p0(ptr %alloca.b) + + ret <3 x float> %v +} + +declare void @escape(ptr) _______________________________________________ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
