[llvm] [InstCombine] Remove OneUse clause from `((A+B)+B) → A+2*B` (PR #80705)
Ricardo Jesus via llvm-commits
llvm-commits at lists.llvm.org
Mon Feb 5 08:21:00 PST 2024
https://github.com/rj-jesus created https://github.com/llvm/llvm-project/pull/80705
This patch removes the `m_OneUse` check that was being done for the following patterns:
(A + RHS) + RHS --> A + (RHS << 1)
LHS + (A + LHS) --> A + (LHS << 1)
This may increase the instruction count if (A + RHS) or (A + LHS) are used more than once but will usually help with LICM later on if A is an induction variable.
This is exemplified here: https://godbolt.org/z/q94vbf5e9 - the first instruction of the second iteration ([1,0]) can start much earlier on with the patch, allowing for significantly higher IPC.
I've benchmarked this with RAJAPerf on a Grace system and see an overall performance uplift of 2% across the whole benchmark which comes mainly from ~45% uplifts in three kernels. Worst I saw was a 1.2% slowdown on a single kernel which I look into later.
Please let me know if I should move this elsewhere!
>From ee897e69393452cde3ce5174ccd6029953eddd91 Mon Sep 17 00:00:00 2001
From: Ricardo Jesus <rjj at ed.ac.uk>
Date: Mon, 5 Feb 2024 13:53:06 +0000
Subject: [PATCH] =?UTF-8?q?[InstCombine]=20Remove=20OneUse=20clause=20from?=
=?UTF-8?q?=20`((A+B)+B)=20=E2=86=92=20A+2*B`?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
This patch removes the `m_OneUse` check that was being done for the
following patterns:
(A + RHS) + RHS --> A + (RHS << 1)
LHS + (A + LHS) --> A + (LHS << 1)
This may increase the instruction count if (A + RHS) or (A + LHS) are
used more than once but usually will help with LICM later on if A is an
induction variable.
---
llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp b/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
index 8a00b75a1f740..984f7a619d4ab 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
@@ -1521,11 +1521,14 @@ Instruction *InstCombinerImpl::visitAdd(BinaryOperator &I) {
return BinaryOperator::CreateSub(A, B);
// (A + RHS) + RHS --> A + (RHS << 1)
- if (match(LHS, m_OneUse(m_c_Add(m_Value(A), m_Specific(RHS)))))
+ // This may increase instruction count if (A + RHS) is used more than once
+ // but helps make (RHS << 1) suitable for potential LICM.
+ if (match(LHS, m_c_Add(m_Value(A), m_Specific(RHS))))
return BinaryOperator::CreateAdd(A, Builder.CreateShl(RHS, 1, "reass.add"));
// LHS + (A + LHS) --> A + (LHS << 1)
- if (match(RHS, m_OneUse(m_c_Add(m_Value(A), m_Specific(LHS)))))
+ // Same as above.
+ if (match(RHS, m_c_Add(m_Value(A), m_Specific(LHS))))
return BinaryOperator::CreateAdd(A, Builder.CreateShl(LHS, 1, "reass.add"));
{
More information about the llvm-commits
mailing list