Skip to content

Conversation

@artagnon
Copy link
Contributor

@artagnon artagnon commented Aug 4, 2025

This patch is motivated by wanting to do CSE at the VPlan-level: as VPlan stores FMF and GEPNoWrapFlags among other things in its recipes, de-duplicating them for common-subexpression-elimination would require hashing the VPlan recipes along with their embedded information.

This patch is motivated by wanting to do CSE at the VPlan-level: as
VPlan stores FMF and GEPNoWrapFlags among other things in its recipes,
de-duplicating them for common-subexpression-elimination would require
hashing the VPlan recipes along with their embedded information.
@artagnon artagnon requested review from fhahn and nikic August 4, 2025 11:29
@llvmbot llvmbot added the llvm:ir label Aug 4, 2025
@llvmbot
Copy link
Member

llvmbot commented Aug 4, 2025

@llvm/pr-subscribers-llvm-ir

Author: Ramkumar Ramachandra (artagnon)

Changes

This patch is motivated by wanting to do CSE at the VPlan-level: as VPlan stores FMF and GEPNoWrapFlags among other things in its recipes, de-duplicating them for common-subexpression-elimination would require hashing the VPlan recipes along with their embedded information.


Full diff: https://github.com/llvm/llvm-project/pull/151946.diff

2 Files Affected:

  • (modified) llvm/include/llvm/IR/FMF.h (+7)
  • (modified) llvm/include/llvm/IR/GEPNoWrapFlags.h (+7)
diff --git a/llvm/include/llvm/IR/FMF.h b/llvm/include/llvm/IR/FMF.h
index 8bd591250a38a..da4d9f564bd5d 100644
--- a/llvm/include/llvm/IR/FMF.h
+++ b/llvm/include/llvm/IR/FMF.h
@@ -13,6 +13,7 @@
 #ifndef LLVM_IR_FMF_H
 #define LLVM_IR_FMF_H
 
+#include "llvm/ADT/Hashing.h"
 #include "llvm/Support/Compiler.h"
 
 namespace llvm {
@@ -121,6 +122,9 @@ class FastMathFlags {
     const unsigned ValueMask = NoNaNs | NoInfs | NoSignedZeros;
     return FastMathFlags(ValueMask & (LHS.Flags | RHS.Flags));
   }
+
+  // Hashing.
+  friend hash_code hash_value(const FastMathFlags &FMF);
 };
 
 inline FastMathFlags operator|(FastMathFlags LHS, FastMathFlags RHS) {
@@ -138,6 +142,9 @@ inline raw_ostream &operator<<(raw_ostream &O, FastMathFlags FMF) {
   return O;
 }
 
+inline hash_code hash_value(const FastMathFlags &FMF) {
+  return hash_value(FMF.Flags);
+}
 } // end namespace llvm
 
 #endif // LLVM_IR_FMF_H
diff --git a/llvm/include/llvm/IR/GEPNoWrapFlags.h b/llvm/include/llvm/IR/GEPNoWrapFlags.h
index 4e6ab0d88bfcf..35974b323d1e1 100644
--- a/llvm/include/llvm/IR/GEPNoWrapFlags.h
+++ b/llvm/include/llvm/IR/GEPNoWrapFlags.h
@@ -13,6 +13,7 @@
 #ifndef LLVM_IR_GEPNOWRAPFLAGS_H
 #define LLVM_IR_GEPNOWRAPFLAGS_H
 
+#include "llvm/ADT/Hashing.h"
 #include <assert.h>
 
 namespace llvm {
@@ -101,8 +102,14 @@ class GEPNoWrapFlags {
     Flags |= Other.Flags;
     return *this;
   }
+
+  // Hashing.
+  friend hash_code hash_value(const GEPNoWrapFlags &NW);
 };
 
+inline hash_code hash_value(const GEPNoWrapFlags &NW) {
+  return hash_value(NW.Flags);
+}
 } // end namespace llvm
 
 #endif // LLVM_IR_GEPNOWRAPFLAGS_H

Copy link
Contributor

@fhahn fhahn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that's needed. Same as IR CSE, we should drop the flags when re-using a value

@artagnon artagnon closed this Aug 4, 2025
@artagnon artagnon deleted the ir-hashflags branch August 4, 2025 11:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants