[llvm] [GVN] No need to swap if both LHS and RHS are arguments (PR #95566)

via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 14 15:08:42 PDT 2024


https://github.com/hiraditya updated https://github.com/llvm/llvm-project/pull/95566

>From f897c99009eb25096de2b6b7d851d06acd0e4a3b Mon Sep 17 00:00:00 2001
From: AdityaK <hiraditya at msn.com>
Date: Fri, 14 Jun 2024 09:49:22 -0700
Subject: [PATCH] No need to swap if both LHS and RHS are arguments

---
 llvm/lib/Transforms/Scalar/GVN.cpp | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/llvm/lib/Transforms/Scalar/GVN.cpp b/llvm/lib/Transforms/Scalar/GVN.cpp
index b5be8ac249417..747b963db312d 100644
--- a/llvm/lib/Transforms/Scalar/GVN.cpp
+++ b/llvm/lib/Transforms/Scalar/GVN.cpp
@@ -2472,7 +2472,8 @@ bool GVNPass::propagateEquality(Value *LHS, Value *RHS,
       continue;
 
     // Prefer a constant on the right-hand side, or an Argument if no constants.
-    if (isa<Constant>(LHS) || (isa<Argument>(LHS) && !isa<Constant>(RHS)))
+    if (isa<Constant>(LHS) ||
+	(isa<Argument>(LHS) && !isa<Argument>(RHS) && !isa<Constant>(RHS)))
       std::swap(LHS, RHS);
     assert((isa<Argument>(LHS) || isa<Instruction>(LHS)) && "Unexpected value!");
     const DataLayout &DL =



More information about the llvm-commits mailing list