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

via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 3 06:31:34 PST 2026


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-transforms

Author: Madhur Amilkanthwar (madhur13490)

<details>
<summary>Changes</summary>

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

---
Full diff: https://github.com/llvm/llvm-project/pull/184347.diff


2 Files Affected:

- (modified) llvm/lib/Transforms/Utils/VNCoercion.cpp (+1-1) 
- (added) llvm/test/svcount-access.ll (+16) 


``````````diff
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
+}

``````````

</details>


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


More information about the llvm-commits mailing list