[llvm] [NFC] Replace m_Sub(m_Zero(), X) with m_Neg(X) (PR #88461)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 11 16:45:59 PDT 2024
https://github.com/AtariDreams created https://github.com/llvm/llvm-project/pull/88461
None
>From e9f355cc6d540e98709ce186b8b799b5a82ad5b8 Mon Sep 17 00:00:00 2001
From: Rose <gfunni234 at gmail.com>
Date: Thu, 11 Apr 2024 19:45:26 -0400
Subject: [PATCH] [NFC] Replace m_Sub(m_Zero(), X) with m_Neg(X)
---
llvm/lib/Analysis/InstructionSimplify.cpp | 2 +-
llvm/lib/Analysis/ValueTracking.cpp | 4 ++--
llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp | 2 +-
llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp | 6 +++---
4 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp
index 3c943a09a9c232..1aaa4d658803bd 100644
--- a/llvm/lib/Analysis/InstructionSimplify.cpp
+++ b/llvm/lib/Analysis/InstructionSimplify.cpp
@@ -5052,7 +5052,7 @@ static Value *simplifyGEPInst(Type *SrcTy, Value *Ptr,
// gep (gep V, C), (sub 0, V) -> C
if (match(Indices.back(),
- m_Sub(m_Zero(), m_PtrToInt(m_Specific(StrippedBasePtr)))) &&
+ m_Neg(m_PtrToInt(m_Specific(StrippedBasePtr)))) &&
!BasePtrOffset.isZero()) {
auto *CI = ConstantInt::get(GEPTy->getContext(), BasePtrOffset);
return ConstantExpr::getIntToPtr(CI, GEPTy);
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp
index eb8925c5347537..ca257cc6aefdfa 100644
--- a/llvm/lib/Analysis/ValueTracking.cpp
+++ b/llvm/lib/Analysis/ValueTracking.cpp
@@ -8016,12 +8016,12 @@ bool llvm::isKnownNegation(const Value *X, const Value *Y, bool NeedNSW) {
// X = sub (0, Y) || X = sub nsw (0, Y)
if ((!NeedNSW && match(X, m_Sub(m_ZeroInt(), m_Specific(Y)))) ||
- (NeedNSW && match(X, m_NSWSub(m_ZeroInt(), m_Specific(Y)))))
+ (NeedNSW && match(X, m_NSWNeg(m_Specific(Y)))))
return true;
// Y = sub (0, X) || Y = sub nsw (0, X)
if ((!NeedNSW && match(Y, m_Sub(m_ZeroInt(), m_Specific(X)))) ||
- (NeedNSW && match(Y, m_NSWSub(m_ZeroInt(), m_Specific(X)))))
+ (NeedNSW && match(Y, m_NSWNeg(m_Specific(X)))))
return true;
// X = sub (A, B), Y = sub (B, A) || X = sub nsw (A, B), Y = sub nsw (B, A)
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
index 1dd0fa49a460f8..e002cf1d1de381 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
@@ -4308,7 +4308,7 @@ bool SelectionDAG::isKnownToBeAPowerOfTwo(SDValue Val, unsigned Depth) const {
// x & -x -> non-zero pow2
// so if we find the pattern return whether we know `x` is non-zero.
SDValue X;
- if (sd_match(Val, m_And(m_Value(X), m_Sub(m_Zero(), m_Deferred(X)))))
+ if (sd_match(Val, m_And(m_Value(X), m_Neg(m_Deferred(X)))))
return isKnownNeverZero(X, Depth);
if (Val.getOpcode() == ISD::ZERO_EXTEND)
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp b/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
index 8c698e52b5a0e6..c79f8d7b59ff60 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
@@ -1573,7 +1573,7 @@ Instruction *InstCombinerImpl::visitSDiv(BinaryOperator &I) {
// TODO: This could be enhanced to handle arbitrary vector constants by
// checking if all elements are not the min-signed-val.
if (!Op1C->isMinSignedValue() &&
- match(Op0, m_NSWSub(m_Zero(), m_Value(X)))) {
+ match(Op0, m_Neg(m_Value(X)))) {
Constant *NegC = ConstantInt::get(Ty, -(*Op1C));
Instruction *BO = BinaryOperator::CreateSDiv(X, NegC);
BO->setIsExact(I.isExact());
@@ -1583,7 +1583,7 @@ Instruction *InstCombinerImpl::visitSDiv(BinaryOperator &I) {
// -X / Y --> -(X / Y)
Value *Y;
- if (match(&I, m_SDiv(m_OneUse(m_NSWSub(m_Zero(), m_Value(X))), m_Value(Y))))
+ if (match(&I, m_SDiv(m_OneUse(m_Neg((), m_Value(X))), m_Value(Y))))
return BinaryOperator::CreateNSWNeg(
Builder.CreateSDiv(X, Y, I.getName(), I.isExact()));
@@ -2173,7 +2173,7 @@ Instruction *InstCombinerImpl::visitSRem(BinaryOperator &I) {
// -X srem Y --> -(X srem Y)
Value *X, *Y;
- if (match(&I, m_SRem(m_OneUse(m_NSWSub(m_Zero(), m_Value(X))), m_Value(Y))))
+ if (match(&I, m_SRem(m_OneUse(m_Neg((), m_Value(X))), m_Value(Y))))
return BinaryOperator::CreateNSWNeg(Builder.CreateSRem(X, Y));
// If the sign bits of both operands are zero (i.e. we can prove they are
More information about the llvm-commits
mailing list