[llvm] 63725ab - [RISCV] Add test for aliasing miscompile fixed by #83017. NFC
Luke Lau via llvm-commits
llvm-commits at lists.llvm.org
Sun Mar 3 23:47:41 PST 2024
Author: Luke Lau
Date: 2024-03-04T15:45:26+08:00
New Revision: 63725ab1196ac50509ad382fc12c56f6d8b5d874
URL: https://github.com/llvm/llvm-project/commit/63725ab1196ac50509ad382fc12c56f6d8b5d874
DIFF: https://github.com/llvm/llvm-project/commit/63725ab1196ac50509ad382fc12c56f6d8b5d874.diff
LOG: [RISCV] Add test for aliasing miscompile fixed by #83017. NFC
Previously we incorrectly removed the scalar load store pair here assuming it
was dead, when it actually aliased with the memset. This showed up as a
miscompile on SPEC CPU 2017 when compiling with -mrvv-vector-bits, and was only
triggered by the changes in #75531. This was fixed in #83017, but this patch
adds a test case for this specific miscompile.
For reference, the incorrect codegen was:
vsetvli a1, zero, e8, m4, ta, ma
vmv.v.i v8, 0
vs4r.v v8, (a0)
addi a1, a0, 80
vsetivli zero, 16, e8, m1, ta, ma
vmv.v.i v8, 0
vs1r.v v8, (a1)
addi a0, a0, 64
vs1r.v v8, (a0)
Added:
llvm/test/CodeGen/RISCV/rvv/pr83017.ll
Modified:
Removed:
################################################################################
diff --git a/llvm/test/CodeGen/RISCV/rvv/pr83017.ll b/llvm/test/CodeGen/RISCV/rvv/pr83017.ll
new file mode 100644
index 00000000000000..3719a2ad994d6f
--- /dev/null
+++ b/llvm/test/CodeGen/RISCV/rvv/pr83017.ll
@@ -0,0 +1,50 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 4
+; RUN: llc < %s -mtriple=riscv64 -mattr=+v -riscv-v-vector-bits-max=128 -verify-machineinstrs | FileCheck %s
+
+; This showcases a miscompile that was fixed in #83107:
+; - The memset will be type-legalized to a 512 bit store + 2 x 128 bit stores.
+; - the load and store of q aliases the upper 128 bits store of p.
+; - The aliasing 128 bit store will be between the chain of the scalar
+; load/store:
+;
+; t54: ch = store<(store (s512) into %ir.p, align 1)> t0, ...
+; t51: ch = store<(store (s128) into %ir.p + 64, align 1)> t0, ...
+;
+; t44: i64,ch = load<(load (s32) from %ir.q), sext from i32> t0, ...
+; t50: ch = store<(store (s128) into %ir.p + 80, align 1)> t44:1, ...
+; t46: ch = store<(store (s32) into %ir.q), trunc to i32> t50, ...
+;
+; Previously, the scalar load/store was incorrectly combined away:
+;
+; t54: ch = store<(store (s512) into %ir.p, align 1)> t0, ...
+; t51: ch = store<(store (s128) into %ir.p + 64, align 1)> t0, ...
+;
+; // MISSING
+; t50: ch = store<(store (s128) into %ir.p + 80, align 1)> t44:1, ...
+; // MISSING
+;
+; - We need to compile with an exact VLEN so that we select an ISD::STORE node
+; which triggers the combine
+; - The miscompile doesn't happen if we use separate GEPs as we need the stores
+; to share the same MachinePointerInfo
+define void @aliasing(ptr %p) {
+; CHECK-LABEL: aliasing:
+; CHECK: # %bb.0:
+; CHECK-NEXT: lw a1, 84(a0)
+; CHECK-NEXT: addi a2, a0, 80
+; CHECK-NEXT: vsetivli zero, 16, e8, m1, ta, ma
+; CHECK-NEXT: vmv.v.i v8, 0
+; CHECK-NEXT: vs1r.v v8, (a2)
+; CHECK-NEXT: vsetvli a2, zero, e8, m4, ta, ma
+; CHECK-NEXT: vmv.v.i v12, 0
+; CHECK-NEXT: vs4r.v v12, (a0)
+; CHECK-NEXT: addi a2, a0, 64
+; CHECK-NEXT: vs1r.v v8, (a2)
+; CHECK-NEXT: sw a1, 84(a0)
+; CHECK-NEXT: ret
+ %q = getelementptr inbounds i8, ptr %p, i64 84
+ %tmp = load i32, ptr %q
+ tail call void @llvm.memset.p0.i64(ptr %p, i8 0, i64 96, i1 false)
+ store i32 %tmp, ptr %q
+ ret void
+}
More information about the llvm-commits
mailing list