[llvm] [InstCombine] Regard zext nneg as sext when folding add(zext neg(add)) (PR #88887)

via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 16 05:35:03 PDT 2024


https://github.com/ZelinMa557 created https://github.com/llvm/llvm-project/pull/88887

fix the issue https://github.com/llvm/llvm-project/issues/88348

>From c00d2bce89a1261f4807c27da41b049f81f58253 Mon Sep 17 00:00:00 2001
From: ZelinMa557 <3388706467 at qq.com>
Date: Tue, 16 Apr 2024 20:33:43 +0800
Subject: [PATCH] [InstCombine] Regard zext nneg as sext when folding add(zext
 neg(add))

Signed-off-by: ZelinMa557 <3388706467 at qq.com>
---
 llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp b/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
index 07c50d866544b3..e659b5de395b35 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
@@ -828,9 +828,10 @@ static Instruction *foldNoWrapAdd(BinaryOperator &Add,
 
   // More general combining of constants in the wide type.
   // (sext (X +nsw NarrowC)) + C --> (sext X) + (sext(NarrowC) + C)
+  // or (zext nneg (X +nsw NarrowC)) + C --> (sext X) + (sext(NarrowC) + C)
   Constant *NarrowC;
-  if (match(Op0,
-            m_OneUse(m_SExt(m_NSWAddLike(m_Value(X), m_Constant(NarrowC)))))) {
+  if (match(Op0, m_OneUse(m_SExtLike(
+                     m_NSWAddLike(m_Value(X), m_Constant(NarrowC)))))) {
     Value *WideC = Builder.CreateSExt(NarrowC, Ty);
     Value *NewC = Builder.CreateAdd(WideC, Op1C);
     Value *WideX = Builder.CreateSExt(X, Ty);
@@ -844,7 +845,6 @@ static Instruction *foldNoWrapAdd(BinaryOperator &Add,
     Value *WideX = Builder.CreateZExt(X, Ty);
     return BinaryOperator::CreateAdd(WideX, NewC);
   }
-
   return nullptr;
 }
 



More information about the llvm-commits mailing list