[llvm] [BasicAA] Remove special malloc handling (PR #197180)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Tue May 12 05:55:04 PDT 2026


https://github.com/nikic created https://github.com/llvm/llvm-project/pull/197180

None

>From aef87c4f340e9d281604ef690c7e7e52e3b0a2bd Mon Sep 17 00:00:00 2001
From: Nikita Popov <npopov at redhat.com>
Date: Tue, 12 May 2026 14:53:56 +0200
Subject: [PATCH] [BasicAA] Remove special malloc handling

---
 llvm/lib/Analysis/BasicAliasAnalysis.cpp | 14 --------------
 llvm/test/Transforms/GVN/nonescaping.ll  | 21 +++++++--------------
 2 files changed, 7 insertions(+), 28 deletions(-)

diff --git a/llvm/lib/Analysis/BasicAliasAnalysis.cpp b/llvm/lib/Analysis/BasicAliasAnalysis.cpp
index 8b120f0ad1e11..9ba514d46baa5 100644
--- a/llvm/lib/Analysis/BasicAliasAnalysis.cpp
+++ b/llvm/lib/Analysis/BasicAliasAnalysis.cpp
@@ -1029,20 +1029,6 @@ ModRefInfo BasicAAResult::getModRefInfo(const CallBase *Call,
   if (!isModAndRefSet(Result))
     return Result;
 
-  // If the call is malloc/calloc like, we can assume that it doesn't
-  // modify any IR visible value.  This is only valid because we assume these
-  // routines do not read values visible in the IR.  TODO: Consider special
-  // casing realloc and strdup routines which access only their arguments as
-  // well.  Or alternatively, replace all of this with inaccessiblememonly once
-  // that's implemented fully.
-  if (isMallocOrCallocLikeFn(Call, &TLI)) {
-    // Be conservative if the accessed pointer may alias the allocation -
-    // fallback to the generic handling below.
-    if (AAQI.AAR.alias(MemoryLocation::getBeforeOrAfter(Call), Loc, AAQI) ==
-        AliasResult::NoAlias)
-      return ModRefInfo::NoModRef;
-  }
-
   // Like assumes, invariant.start intrinsics were also marked as arbitrarily
   // writing so that proper control dependencies are maintained but they never
   // mod any particular memory location visible to the IR.
diff --git a/llvm/test/Transforms/GVN/nonescaping.ll b/llvm/test/Transforms/GVN/nonescaping.ll
index 0866a27b249f5..09f3712e6cdda 100644
--- a/llvm/test/Transforms/GVN/nonescaping.ll
+++ b/llvm/test/Transforms/GVN/nonescaping.ll
@@ -54,18 +54,13 @@ define i8 @test_calloc(ptr %p) {
 }
 
 define i8 @test_opnew(ptr %p) {
-; MDEP-LABEL: @test_opnew(
-; MDEP-NEXT:    [[OBJ:%.*]] = call ptr @_Znwm(i64 16)
-; MDEP-NEXT:    call void @escape(ptr [[OBJ]])
-; MDEP-NEXT:    ret i8 0
-;
-; MSSA-LABEL: @test_opnew(
-; MSSA-NEXT:    [[V1:%.*]] = load i8, ptr [[P:%.*]], align 1
-; MSSA-NEXT:    [[OBJ:%.*]] = call ptr @_Znwm(i64 16)
-; MSSA-NEXT:    [[V2:%.*]] = load i8, ptr [[P]], align 1
-; MSSA-NEXT:    [[SUB:%.*]] = sub i8 [[V1]], [[V2]]
-; MSSA-NEXT:    call void @escape(ptr [[OBJ]])
-; MSSA-NEXT:    ret i8 [[SUB]]
+; CHECK-LABEL: @test_opnew(
+; CHECK-NEXT:    [[V1:%.*]] = load i8, ptr [[P:%.*]], align 1
+; CHECK-NEXT:    [[OBJ:%.*]] = call ptr @_Znwm(i64 16)
+; CHECK-NEXT:    [[V2:%.*]] = load i8, ptr [[P]], align 1
+; CHECK-NEXT:    [[SUB:%.*]] = sub i8 [[V1]], [[V2]]
+; CHECK-NEXT:    call void @escape(ptr [[OBJ]])
+; CHECK-NEXT:    ret i8 [[SUB]]
 ;
   %v1 = load i8, ptr %p
   %obj = call ptr @_Znwm(i64 16)
@@ -74,5 +69,3 @@ define i8 @test_opnew(ptr %p) {
   call void @escape(ptr %obj)
   ret i8 %sub
 }
-;; NOTE: These prefixes are unused and the list is autogenerated. Do not add tests below this line:
-; CHECK: {{.*}}



More information about the llvm-commits mailing list