llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

Unstable order of `-pass-remarks-analysis=stack-frame-layout` output

Open alexfh opened this issue 2 years ago • 7 comments

The llvm/test/CodeGen/AArch64/sve-stack-frame-layout.ll test added in 6ae4014befbc16c63c31922d8462afcaae51e260 uncovers a non-determinism in LLVM. There seems to be a dependency on the order of iteration over an unordered container or something like that. The lines printed by emitStackSlotRemark have unstable order (the easiest way to reproduce is to build libc++ and llc with -D_LIBCPP_DEBUG_RANDOMIZE_UNSPECIFIED_STABILITY, see https://libcxx.llvm.org/DesignDocs/UnspecifiedBehaviorRandomization.html):

$ diff -u \
  <(llc <llvm/test/CodeGen/AArch64/sve-stack-frame-layout.ll -mtriple=aarch64 -mattr=+sve2 -pass-remarks-analysis=stack-frame-layout 2>&1 >/dev/null) \
  <(llc <llvm/test/CodeGen/AArch64/sve-stack-frame-layout.ll -mtriple=aarch64 -mattr=+sve2 -pass-remarks-analysis=stack-frame-layout 2>&1 >/dev/null)
--- /dev/fd/63  2024-07-29 16:49:54.964017882 +0200
+++ /dev/fd/62  2024-07-29 16:49:54.964017882 +0200
@@ -1,23 +1,23 @@
 remark: <unknown>:0:0:
 Function: csr_d8_allocnxv4i32i32f64
 Offset: [SP-8], Type: Spill, Align: 8, Size: 8
-Offset: [SP-16], Type: Spill, Align: 8, Size: 8
 Offset: [SP-16], Type: Variable, Align: 16, Size: 16
+Offset: [SP-16], Type: Spill, Align: 8, Size: 8
 Offset: [SP-20], Type: Variable, Align: 4, Size: 4
 Offset: [SP-32], Type: Variable, Align: 8, Size: 8
 remark: <unknown>:0:0:
 Function: csr_d8_allocnxv4i32i32f64_fp
 Offset: [SP-8], Type: Spill, Align: 8, Size: 8
-Offset: [SP-16], Type: Spill, Align: 8, Size: 8
 Offset: [SP-16], Type: Variable, Align: 16, Size: 16
+Offset: [SP-16], Type: Spill, Align: 8, Size: 8
 Offset: [SP-20], Type: Variable, Align: 4, Size: 4
 Offset: [SP-32], Type: Spill, Align: 16, Size: 8
 Offset: [SP-40], Type: Variable, Align: 8, Size: 8
 remark: <unknown>:0:0:
 Function: svecc_z8_allocnxv4i32i32f64_fp
 Offset: [SP-8], Type: Spill, Align: 8, Size: 8
-Offset: [SP-16], Type: Spill, Align: 8, Size: 8
 Offset: [SP-16], Type: Spill, Align: 16, Size: 16
+Offset: [SP-16], Type: Spill, Align: 8, Size: 8
 Offset: [SP-20], Type: Variable, Align: 4, Size: 4
 Offset: [SP-32], Type: Variable, Align: 16, Size: 16
 Offset: [SP-32], Type: Variable, Align: 8, Size: 8

alexfh avatar Jul 29 '24 14:07 alexfh

@llvm/issue-subscribers-backend-aarch64

Author: Alexander Kornienko (alexfh)

The `llvm/test/CodeGen/AArch64/sve-stack-frame-layout.ll` test added in 6ae4014befbc16c63c31922d8462afcaae51e260 uncovers a non-determinism in LLVM. There seems to be a dependency on the order of iteration over an unordered container or something like that. The lines printed by `emitStackSlotRemark` have unstable order (the easiest way to reproduce is to build libc++ and llc with `-D_LIBCPP_DEBUG_RANDOMIZE_UNSPECIFIED_STABILITY`, see https://libcxx.llvm.org/DesignDocs/UnspecifiedBehaviorRandomization.html): ``` $ diff -u \ <(llc <llvm/test/CodeGen/AArch64/sve-stack-frame-layout.ll -mtriple=aarch64 -mattr=+sve2 -pass-remarks-analysis=stack-frame-layout 2>&1 >/dev/null) \ <(llc <llvm/test/CodeGen/AArch64/sve-stack-frame-layout.ll -mtriple=aarch64 -mattr=+sve2 -pass-remarks-analysis=stack-frame-layout 2>&1 >/dev/null) --- /dev/fd/63 2024-07-29 16:49:54.964017882 +0200 +++ /dev/fd/62 2024-07-29 16:49:54.964017882 +0200 @@ -1,23 +1,23 @@ remark: <unknown>:0:0: Function: csr_d8_allocnxv4i32i32f64 Offset: [SP-8], Type: Spill, Align: 8, Size: 8 -Offset: [SP-16], Type: Spill, Align: 8, Size: 8 Offset: [SP-16], Type: Variable, Align: 16, Size: 16 +Offset: [SP-16], Type: Spill, Align: 8, Size: 8 Offset: [SP-20], Type: Variable, Align: 4, Size: 4 Offset: [SP-32], Type: Variable, Align: 8, Size: 8 remark: <unknown>:0:0: Function: csr_d8_allocnxv4i32i32f64_fp Offset: [SP-8], Type: Spill, Align: 8, Size: 8 -Offset: [SP-16], Type: Spill, Align: 8, Size: 8 Offset: [SP-16], Type: Variable, Align: 16, Size: 16 +Offset: [SP-16], Type: Spill, Align: 8, Size: 8 Offset: [SP-20], Type: Variable, Align: 4, Size: 4 Offset: [SP-32], Type: Spill, Align: 16, Size: 8 Offset: [SP-40], Type: Variable, Align: 8, Size: 8 remark: <unknown>:0:0: Function: svecc_z8_allocnxv4i32i32f64_fp Offset: [SP-8], Type: Spill, Align: 8, Size: 8 -Offset: [SP-16], Type: Spill, Align: 8, Size: 8 Offset: [SP-16], Type: Spill, Align: 16, Size: 16 +Offset: [SP-16], Type: Spill, Align: 8, Size: 8 Offset: [SP-20], Type: Variable, Align: 4, Size: 4 Offset: [SP-32], Type: Variable, Align: 16, Size: 16 Offset: [SP-32], Type: Variable, Align: 8, Size: 8 ```

llvmbot avatar Jul 29 '24 15:07 llvmbot

Does this still happen with the latest trunk? #99883 should have updated the order, and it has changed again since.

davemgreen avatar Jul 29 '24 15:07 davemgreen

Oh - do you mean this happens on the branch but not trunk? If so yes we should probably port the patches over.

davemgreen avatar Jul 29 '24 15:07 davemgreen

It looks like the branch should have #99883 too.

davemgreen avatar Jul 29 '24 15:07 davemgreen

You're right, https://github.com/llvm/llvm-project/pull/99883 fixes this particular issue. However, the llvm/test/CodeGen/AArch64/sve-stack-frame-layout.ll test is still flaky at a later revision (51d4980a133db12888207698e39c469cb7055cac) in our setup for some reason. I'll investigate and come back with the details.

alexfh avatar Jul 29 '24 19:07 alexfh

Preliminary analysis shows that dc1c00f6b13f724154f9883990f8b21fb8dcccef introduced flakiness again.

alexfh avatar Jul 29 '24 19:07 alexfh

And e31794f99d72dd764c4bc5c5583a0a4c89df22c3 fixes the flakiness again. Seems to be resolved.

alexfh avatar Jul 30 '24 01:07 alexfh