[llvm] [CodeGenPrepare] Fix crash with null PSI (PR #173385)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Dec 29 02:03:44 PST 2025
https://github.com/nataliakokoromyti updated https://github.com/llvm/llvm-project/pull/173385
>From b2565139f7e5413488a60c147d84acd1b98311d3 Mon Sep 17 00:00:00 2001
From: Natalia <nataliakokoromyti at gmail.com>
Date: Tue, 23 Dec 2025 06:18:42 -0800
Subject: [PATCH 1/4] add test for issue #173360
---
.../CodeGenPrepare/pr173360-null-psi.ll | 21 +++++++++++++++++++
1 file changed, 21 insertions(+)
create mode 100644 llvm/test/Transforms/CodeGenPrepare/pr173360-null-psi.ll
diff --git a/llvm/test/Transforms/CodeGenPrepare/pr173360-null-psi.ll b/llvm/test/Transforms/CodeGenPrepare/pr173360-null-psi.ll
new file mode 100644
index 0000000000000..53500c0bcb481
--- /dev/null
+++ b/llvm/test/Transforms/CodeGenPrepare/pr173360-null-psi.ll
@@ -0,0 +1,21 @@
+; NOTE: This test verifies that CodeGenPrepare doesn't crash when PSI is null
+; RUN: opt -passes=codegenprepare < %s -S | FileCheck %s
+;
+; This test case triggered a null pointer dereference in CodeGenPrepare::_run()
+; when ProfileSummaryInfo (PSI) was not available. The pass attempted to call
+; PSI->hasHugeWorkingSetSize() without checking if PSI was null.
+;
+; The fix adds null checks before dereferencing PSI.
+; See: https://github.com/llvm/llvm-project/issues/173360
+
+target triple = "x86_64-unknown-linux-gnu"
+
+; CHECK-LABEL: @f(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: %iv.next.reg2mem = alloca i32, align 4
+; CHECK-NEXT: ret void
+define void @f(ptr %A, i32 %n) {
+entry:
+ %iv.next.reg2mem = alloca i32, align 4
+ ret void
+}
>From 5cf237b47552ad247b3f9cacca9798e7b189773c Mon Sep 17 00:00:00 2001
From: Natalia <nataliakokoromyti at gmail.com>
Date: Tue, 23 Dec 2025 06:49:56 -0800
Subject: [PATCH 2/4] trigger CI
>From 3f6f3ed5e06dad9356835569b7fd1534a4f838d1 Mon Sep 17 00:00:00 2001
From: Natalia <nataliakokoromyti at gmail.com>
Date: Tue, 23 Dec 2025 06:53:01 -0800
Subject: [PATCH 3/4] trigger CI
>From dc17e4fc6bce1c3af29a47b8ac4d846a5cf8583d Mon Sep 17 00:00:00 2001
From: Natalia <nataliakokoromyti at gmail.com>
Date: Mon, 29 Dec 2025 01:49:08 -0800
Subject: [PATCH 4/4] fix formatting
---
llvm/lib/CodeGen/CodeGenPrepare.cpp | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/llvm/lib/CodeGen/CodeGenPrepare.cpp b/llvm/lib/CodeGen/CodeGenPrepare.cpp
index 01f49b8ecccff..ee1ad6de57770 100644
--- a/llvm/lib/CodeGen/CodeGenPrepare.cpp
+++ b/llvm/lib/CodeGen/CodeGenPrepare.cpp
@@ -585,7 +585,7 @@ bool CodeGenPrepare::_run(Function &F) {
if (BBSectionsGuidedSectionPrefix && BBSectionsProfileReader &&
BBSectionsProfileReader->isFunctionHot(F.getName())) {
(void)F.setSectionPrefix("hot");
- } else if (ProfileGuidedSectionPrefix) {
+ } else if (ProfileGuidedSectionPrefix && PSI) {
// The hot attribute overwrites profile count based hotness while profile
// counts based hotness overwrite the cold attribute.
// This is a conservative behabvior.
@@ -605,7 +605,8 @@ bool CodeGenPrepare::_run(Function &F) {
/// This optimization identifies DIV instructions that can be
/// profitably bypassed and carried out with a shorter, faster divide.
- if (!OptSize && !PSI->hasHugeWorkingSetSize() && TLI->isSlowDivBypassed()) {
+ if (!OptSize && PSI && !PSI->hasHugeWorkingSetSize() &&
+ TLI->isSlowDivBypassed()) {
const DenseMap<unsigned int, unsigned int> &BypassWidths =
TLI->getBypassSlowDivWidths();
BasicBlock *BB = &*F.begin();
More information about the llvm-commits
mailing list