[llvm] [InstCombine] Freeze can be avoided if we propagate NUW or NSW (PR #96261)

via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 20 17:56:46 PDT 2024


https://github.com/AtariDreams created https://github.com/llvm/llvm-project/pull/96261

None

>From 4a1b0d8a52a27fe7cc305d5547c8aa41c9a8d779 Mon Sep 17 00:00:00 2001
From: Rose <gfunni234 at gmail.com>
Date: Thu, 20 Jun 2024 20:56:05 -0400
Subject: [PATCH] [InstCombine] Freeze can be avoided if we propagate NUW or
 NSW

---
 llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp b/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
index 8fcb3544f682a..ff4c72074312b 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
@@ -166,7 +166,9 @@ static Value *foldMulShl1(BinaryOperator &Mul, bool CommuteOperands,
   if (match(Y, m_OneUse(m_Add(m_BinOp(Shift), m_One()))) &&
       match(Shift, m_OneUse(m_Shl(m_One(), m_Value(Z))))) {
     bool PropagateNSW = HasNSW && Shift->hasNoSignedWrap();
-    Value *FrX = Builder.CreateFreeze(X, X->getName() + ".fr");
+    Value* FrX = X;
+    if (!HasNUW && !HasNSW)
+      FrX = Builder.CreateFreeze(X, X->getName() + ".fr");
     Value *Shl = Builder.CreateShl(FrX, Z, "mulshl", HasNUW, PropagateNSW);
     return Builder.CreateAdd(Shl, FrX, Mul.getName(), HasNUW, PropagateNSW);
   }



More information about the llvm-commits mailing list