Skip to content

Conversation

madhur13490
Copy link
Contributor

@madhur13490 madhur13490 commented Oct 7, 2025

This is an alternative patch to #144987, adding support in GVN.

@madhur13490 madhur13490 requested review from fhahn and nikic October 7, 2025 10:20
Copy link

github-actions bot commented Oct 7, 2025

⚠️ C/C++ code formatter, clang-format found issues in your code. ⚠️

You can test this locally with the following command:
git-clang-format --diff origin/main HEAD --extensions h,cpp -- llvm/include/llvm/Transforms/Scalar/GVN.h llvm/lib/Transforms/Scalar/GVN.cpp

⚠️
The reproduction instructions above might return results for more than one PR
in a stack if you are using a stacked PR workflow. You can limit the results by
changing origin/main to the base branch/commit you want to compare against.
⚠️

View the diff from clang-format here.
diff --git a/llvm/include/llvm/Transforms/Scalar/GVN.h b/llvm/include/llvm/Transforms/Scalar/GVN.h
index a73d17b06..a4aefac43 100644
--- a/llvm/include/llvm/Transforms/Scalar/GVN.h
+++ b/llvm/include/llvm/Transforms/Scalar/GVN.h
@@ -19,10 +19,10 @@
 #include "llvm/ADT/MapVector.h"
 #include "llvm/ADT/SetVector.h"
 #include "llvm/ADT/SmallVector.h"
+#include "llvm/Analysis/LoopInfo.h"
 #include "llvm/IR/Dominators.h"
 #include "llvm/IR/InstrTypes.h"
 #include "llvm/IR/PassManager.h"
-#include "llvm/Analysis/LoopInfo.h"
 #include "llvm/IR/ValueHandle.h"
 #include "llvm/Support/Allocator.h"
 #include "llvm/Support/Compiler.h"
@@ -411,7 +411,7 @@ private:
   void addDeadBlock(BasicBlock *BB);
   void assignValNumForDeadCode();
   void assignBlockRPONumber(Function &F);
-  
+
   bool optimizeMinMaxFindingSelectPattern(SelectInst *Select);
 };
 
diff --git a/llvm/lib/Transforms/Scalar/GVN.cpp b/llvm/lib/Transforms/Scalar/GVN.cpp
index 76653e1a0..d34e9afaa 100644
--- a/llvm/lib/Transforms/Scalar/GVN.cpp
+++ b/llvm/lib/Transforms/Scalar/GVN.cpp
@@ -3531,7 +3531,6 @@ bool GVNPass::optimizeMinMaxFindingSelectPattern(SelectInst *Select) {
   return false;
 }
 
-
 class llvm::gvn::GVNLegacyPass : public FunctionPass {
 public:
   static char ID; // Pass identification, replacement for typeid.

@madhur13490
Copy link
Contributor Author

Hi @fhahn and @nikic,
This patch requires some cosmetic changes. My concern is this is to understand if this what GVN should do?

The patch is functionally correct as the rnflow application passes. However, compared to trunk this patch regresses the app by ~10-12% as the new select instruction the pass is generating is more constly than hoisting the load. I played around SelectOptimize.cpp by turning on --disable-loop-level-heuristics. That helps a bit but still ~10% regression persists.

@david-arm
Copy link
Contributor

The patch is functionally correct as the rnflow application passes. However, compared to trunk this patch regresses the app by ~10-12% as the new select instruction the pass is generating is more constly than hoisting the load. I played around SelectOptimize.cpp by turning on --disable-loop-level-heuristics. That helps a bit but still ~10% regression persists.

In the test you've added the original IR seems to already have a select instruction - do you also see a select in rnflow prior to GVN?

@david-arm
Copy link
Contributor

Sorry, please ignore me! I see there is an extra select being generated. Got it. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants