[llvm] [GVN] Fix crash when svcount is used with globals-aa (PR #184347)

Madhur Amilkanthwar via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 3 06:56:27 PST 2026


https://github.com/madhur13490 updated https://github.com/llvm/llvm-project/pull/184347

>From 5779b26dec93b5f5c6aaa11010dcfe81919f29dd Mon Sep 17 00:00:00 2001
From: Madhur Amilkanthwar <madhura at nvidia.com>
Date: Tue, 3 Mar 2026 06:15:29 -0800
Subject: [PATCH 1/2] [GVN] Fix crash when svcount is used with globals-aa

When -globals-aa is used, `analyzeLoadAvailiability`
calls `analyzeLoadClobberringStore` which in turn calls
`isFirstClassAggregateOrScalableType` which is using
isa<ScalableVectorType>. Ideally it should use type's
isScalableType() method.

The crash does not occur when default (BasicAA) is used
because `analyzeLoadAvailiability` function does not
take the load clobbering path as BasicAA returns `Def`.

Fixes #159368
---
 llvm/lib/Transforms/Utils/VNCoercion.cpp |  2 +-
 llvm/test/svcount-access.ll              | 16 ++++++++++++++++
 2 files changed, 17 insertions(+), 1 deletion(-)
 create mode 100644 llvm/test/svcount-access.ll

diff --git a/llvm/lib/Transforms/Utils/VNCoercion.cpp b/llvm/lib/Transforms/Utils/VNCoercion.cpp
index 03306daeeafce..0dabd065b6723 100644
--- a/llvm/lib/Transforms/Utils/VNCoercion.cpp
+++ b/llvm/lib/Transforms/Utils/VNCoercion.cpp
@@ -10,7 +10,7 @@ using namespace llvm;
 using namespace VNCoercion;
 
 static bool isFirstClassAggregateOrScalableType(Type *Ty) {
-  return Ty->isStructTy() || Ty->isArrayTy() || isa<ScalableVectorType>(Ty);
+  return Ty->isStructTy() || Ty->isArrayTy() || Ty->isScalableTy();
 }
 
 /// Return true if coerceAvailableValueToLoadType will succeed.
diff --git a/llvm/test/svcount-access.ll b/llvm/test/svcount-access.ll
new file mode 100644
index 0000000000000..75a913c9b6763
--- /dev/null
+++ b/llvm/test/svcount-access.ll
@@ -0,0 +1,16 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 6
+; RUN: opt -passes=gvn -aa-pipeline=globals-aa -S < %s | FileCheck %s
+
+define target("aarch64.svcount") @test_alloca_store_reload(target("aarch64.svcount") %val) nounwind {
+; CHECK-LABEL: define target("aarch64.svcount") @test_alloca_store_reload(
+; CHECK-SAME: target("aarch64.svcount") [[VAL:%.*]]) #[[ATTR0:[0-9]+]] {
+; CHECK-NEXT:    [[PTR:%.*]] = alloca target("aarch64.svcount"), align 1
+; CHECK-NEXT:    store target("aarch64.svcount") [[VAL]], ptr [[PTR]], align 2
+; CHECK-NEXT:    [[RES:%.*]] = load target("aarch64.svcount"), ptr [[PTR]], align 2
+; CHECK-NEXT:    ret target("aarch64.svcount") [[RES]]
+;
+  %ptr = alloca target("aarch64.svcount"), align 1
+  store target("aarch64.svcount") %val, ptr %ptr
+  %res = load target("aarch64.svcount"), ptr %ptr
+  ret target("aarch64.svcount") %res
+}

>From 212b052c98a411482c7b49130bc23a3a14c583fe Mon Sep 17 00:00:00 2001
From: Madhur Amilkanthwar <madhura at nvidia.com>
Date: Tue, 3 Mar 2026 06:55:50 -0800
Subject: [PATCH 2/2] fixup! move test to the right location.

---
 llvm/test/{ => Transforms/GVN}/svcount-access.ll | 0
 1 file changed, 0 insertions(+), 0 deletions(-)
 rename llvm/test/{ => Transforms/GVN}/svcount-access.ll (100%)

diff --git a/llvm/test/svcount-access.ll b/llvm/test/Transforms/GVN/svcount-access.ll
similarity index 100%
rename from llvm/test/svcount-access.ll
rename to llvm/test/Transforms/GVN/svcount-access.ll



More information about the llvm-commits mailing list