[llvm] [llvm][NewGVN] Fixing the replacement of incorrect instructions (PR #70599)

via llvm-commits llvm-commits at lists.llvm.org
Sun Oct 29 12:14:23 PDT 2023


https://github.com/knightXun created https://github.com/llvm/llvm-project/pull/70599

issue: https://github.com/llvm/llvm-project/issues/70421

>From 7f9a03270c60c7fc683295004afa752b7fd76be2 Mon Sep 17 00:00:00 2001
From: knightXun <badgangkiller at gmail.com>
Date: Mon, 30 Oct 2023 03:02:08 +0800
Subject: [PATCH] [llvm][NewGVN] Fixing the replacement of incorrect
 instructions  # Please enter the commit message for your changes. Lines
 starting

---
 llvm/lib/Transforms/Scalar/NewGVN.cpp | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/llvm/lib/Transforms/Scalar/NewGVN.cpp b/llvm/lib/Transforms/Scalar/NewGVN.cpp
index 19ac9526b5f88b6..ae65333b270559a 100644
--- a/llvm/lib/Transforms/Scalar/NewGVN.cpp
+++ b/llvm/lib/Transforms/Scalar/NewGVN.cpp
@@ -3066,9 +3066,14 @@ void NewGVN::valueNumberMemoryPhi(MemoryPhi *MP) {
   // Sadly, we can't use std::equals since these are random access iterators.
   const auto *AllSameValue = *MappedBegin;
   ++MappedBegin;
-  bool AllEqual = std::all_of(
-      MappedBegin, MappedEnd,
-      [&AllSameValue](const MemoryAccess *V) { return V == AllSameValue; });
+  bool AllEqual;
+  if (MappedBegin == MappedEnd) {
+    AllEqual = false;
+  } else {
+    AllEqual = std::all_of(
+        MappedBegin, MappedEnd,
+        [&AllSameValue](const MemoryAccess *V) { return V == AllSameValue; });
+  }
 
   if (AllEqual)
     LLVM_DEBUG(dbgs() << "Memory Phi value numbered to " << *AllSameValue



More information about the llvm-commits mailing list