[llvm] [ObjCARC] Add variations of intrinsics that do not touch reference counts (PR #94919)

via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 22 11:01:54 PDT 2024


https://github.com/AtariDreams updated https://github.com/llvm/llvm-project/pull/94919

>From 61f84fed8b73ed42f6e53b7c82e3c8e20c5bcb9d Mon Sep 17 00:00:00 2001
From: Rose <gfunni234 at gmail.com>
Date: Sun, 9 Jun 2024 17:45:26 -0400
Subject: [PATCH 1/2] [ObjCARC] Add variations of intrinsics that do not touch
 reference counts

---
 llvm/lib/Analysis/ObjCARCInstKind.cpp | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/llvm/lib/Analysis/ObjCARCInstKind.cpp b/llvm/lib/Analysis/ObjCARCInstKind.cpp
index d177ee056a93a..370ed88bf57df 100644
--- a/llvm/lib/Analysis/ObjCARCInstKind.cpp
+++ b/llvm/lib/Analysis/ObjCARCInstKind.cpp
@@ -201,8 +201,13 @@ static bool isUseOnlyIntrinsic(unsigned ID) {
   // TODO: Expand this into a covered switch. There is a lot more here.
   switch (ID) {
   case Intrinsic::memcpy:
+  case Intrinsic::memcpy_element_unordered_atomic:
+  case Intrinsic::memcpy_inline:
   case Intrinsic::memmove:
+  case Intrinsic::memmove_element_unordered_atomic:
   case Intrinsic::memset:
+  case Intrinsic::memset_element_unordered_atomic:
+  case Intrinsic::memset_inline:
     return true;
   default:
     return false;

>From 1e5c890d1fd22e347e500028a62238a20e857bef Mon Sep 17 00:00:00 2001
From: Rose <gfunni234 at gmail.com>
Date: Mon, 22 Jul 2024 12:39:08 -0400
Subject: [PATCH 2/2] Add more cases for computeOverflowForSignedAdd

---
 llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
index 02d44cd36ae53..b53697f932f0f 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
@@ -4241,9 +4241,20 @@ SelectionDAG::computeOverflowForSignedAdd(SDValue N0, SDValue N1) const {
   // cannot overflow.
   if (ComputeNumSignBits(N0) > 1 && ComputeNumSignBits(N1) > 1)
     return OFK_Never;
+  
+    // smulhi + any value never overflow
+  KnownBits N1Known = computeKnownBits(N1);
+  if (N0.getOpcode() == ISD::SMUL_LOHI)
+    return OFK_Never;
 
-  // TODO: Add ConstantRange::signedAddMayOverflow handling.
-  return OFK_Sometime;
+  KnownBits N0Known = computeKnownBits(N0);
+  if (N1.getOpcode() == ISD::SMUL_LOHI)
+    return OFK_Never;
+  
+    // Fallback to ConstantRange::signedAddMayOverflow handling.
+  ConstantRange N0Range = ConstantRange::fromKnownBits(N0Known, false);
+  ConstantRange N1Range = ConstantRange::fromKnownBits(N1Known, false);
+  return mapOverflowResult(N0Range.signedAddMayOverflow(N1Range));
 }
 
 SelectionDAG::OverflowKind



More information about the llvm-commits mailing list