[llvm] [IPSCCP] Don't replace with constant if Value is noalias ptr or derivatives (PR #154522)

Bruno De Fraine via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 28 00:49:23 PDT 2025


================
@@ -0,0 +1,47 @@
+; RUN: opt < %s -passes='ipsccp,inline' -S | FileCheck %s
+
+; This test looks if the store from callee after inlining gets the alias.scope
+; If IPSCCP ignores noalias %p ptr and replaces %add.ptr5's GEP %p with @arr,
+; the store will not receive an alias.scope as noalias attribute is lost.
+ at arr = global [100 x i32] zeroinitializer, align 16
+
+define void @caller(i32 noundef %c, i32 noundef %d) #0 {
+; COM: Check that store has both !alias.scope and !noalias
+; CHECK-LABEL: for.body.i:
+; CHECK:  store {{.*}}!alias.scope{{.*}}!noalias
+entry:
+  %idx.ext = sext i32 %d to i64
+  %add.ptr = getelementptr inbounds i32, ptr @arr, i64 %idx.ext
+  %add.ptr4 = getelementptr inbounds i32, ptr %add.ptr, i64 %idx.ext
+  call void @callee(ptr noundef @arr, ptr noundef %add.ptr, ptr noundef %add.ptr4, i32 noundef %d)
+  ret void
+}
+
+define void @callee(ptr noalias noundef %p, ptr noalias noundef %q, ptr noalias noundef %r, i32 noundef %len) #1 align 2 {
----------------
brunodf-snps wrote:

I think the function @callee in your test case needs to be "internal" before IPSCCP can transform it. (Also, the alignment on the function is redundant for the test.)

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


More information about the llvm-commits mailing list