Skip to content

[llvm] Use hash_combine_range with ranges (NFC) #137530

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

kazutakahirata
Copy link
Contributor

No description provided.

@kazutakahirata kazutakahirata requested review from kuhar and nikic April 27, 2025 17:02
@llvmbot llvmbot added vectorizers PGO Profile Guided Optimizations llvm:transforms labels Apr 27, 2025
@llvmbot
Copy link
Member

llvmbot commented Apr 27, 2025

@llvm/pr-subscribers-llvm-transforms

@llvm/pr-subscribers-pgo

Author: Kazu Hirata (kazutakahirata)

Changes

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

5 Files Affected:

  • (modified) llvm/include/llvm/Transforms/Scalar/GVNExpression.h (+1-1)
  • (modified) llvm/lib/ProfileData/Coverage/CoverageMapping.cpp (+1-2)
  • (modified) llvm/lib/Transforms/Scalar/EarlyCSE.cpp (+11-16)
  • (modified) llvm/lib/Transforms/Utils/Local.cpp (+3-3)
  • (modified) llvm/lib/Transforms/Vectorize/LoopVectorize.cpp (+2-2)
diff --git a/llvm/include/llvm/Transforms/Scalar/GVNExpression.h b/llvm/include/llvm/Transforms/Scalar/GVNExpression.h
index 71437953640c9..50cd6ceb9fc0d 100644
--- a/llvm/include/llvm/Transforms/Scalar/GVNExpression.h
+++ b/llvm/include/llvm/Transforms/Scalar/GVNExpression.h
@@ -221,7 +221,7 @@ class BasicExpression : public Expression {
 
   hash_code getHashValue() const override {
     return hash_combine(this->Expression::getHashValue(), ValueType,
-                        hash_combine_range(op_begin(), op_end()));
+                        hash_combine_range(operands()));
   }
 
   // Debugging support
diff --git a/llvm/lib/ProfileData/Coverage/CoverageMapping.cpp b/llvm/lib/ProfileData/Coverage/CoverageMapping.cpp
index c39585681911a..d3fe218c19a14 100644
--- a/llvm/lib/ProfileData/Coverage/CoverageMapping.cpp
+++ b/llvm/lib/ProfileData/Coverage/CoverageMapping.cpp
@@ -933,8 +933,7 @@ Error CoverageMapping::loadFunctionRecord(
   }
 
   // Don't create records for (filenames, function) pairs we've already seen.
-  auto FilenamesHash = hash_combine_range(Record.Filenames.begin(),
-                                          Record.Filenames.end());
+  auto FilenamesHash = hash_combine_range(Record.Filenames);
   if (!RecordProvenance[FilenamesHash].insert(hash_value(OrigFuncName)).second)
     return Error::success();
 
diff --git a/llvm/lib/Transforms/Scalar/EarlyCSE.cpp b/llvm/lib/Transforms/Scalar/EarlyCSE.cpp
index 3a0ae6b01a114..1e378369166c0 100644
--- a/llvm/lib/Transforms/Scalar/EarlyCSE.cpp
+++ b/llvm/lib/Transforms/Scalar/EarlyCSE.cpp
@@ -223,13 +223,11 @@ static unsigned hashCallInst(CallInst *CI) {
   // Don't CSE convergent calls in different basic blocks, because they
   // implicitly depend on the set of threads that is currently executing.
   if (CI->isConvergent()) {
-    return hash_combine(
-        CI->getOpcode(), CI->getParent(),
-        hash_combine_range(CI->value_op_begin(), CI->value_op_end()));
+    return hash_combine(CI->getOpcode(), CI->getParent(),
+                        hash_combine_range(CI->operand_values()));
   }
-  return hash_combine(
-      CI->getOpcode(),
-      hash_combine_range(CI->value_op_begin(), CI->value_op_end()));
+  return hash_combine(CI->getOpcode(),
+                      hash_combine_range(CI->operand_values()));
 }
 
 static unsigned getHashValueImpl(SimpleValue Val) {
@@ -302,12 +300,11 @@ static unsigned getHashValueImpl(SimpleValue Val) {
 
   if (const ExtractValueInst *EVI = dyn_cast<ExtractValueInst>(Inst))
     return hash_combine(EVI->getOpcode(), EVI->getOperand(0),
-                        hash_combine_range(EVI->idx_begin(), EVI->idx_end()));
+                        hash_combine_range(EVI->indices()));
 
   if (const InsertValueInst *IVI = dyn_cast<InsertValueInst>(Inst))
     return hash_combine(IVI->getOpcode(), IVI->getOperand(0),
-                        IVI->getOperand(1),
-                        hash_combine_range(IVI->idx_begin(), IVI->idx_end()));
+                        IVI->getOperand(1), hash_combine_range(IVI->indices()));
 
   assert((isa<CallInst>(Inst) || isa<ExtractElementInst>(Inst) ||
           isa<InsertElementInst>(Inst) || isa<ShuffleVectorInst>(Inst) ||
@@ -322,7 +319,7 @@ static unsigned getHashValueImpl(SimpleValue Val) {
       std::swap(LHS, RHS);
     return hash_combine(
         II->getOpcode(), LHS, RHS,
-        hash_combine_range(II->value_op_begin() + 2, II->value_op_end()));
+        hash_combine_range(drop_begin(II->operand_values(), 2)));
   }
 
   // gc.relocate is 'special' call: its second and third operands are
@@ -338,9 +335,8 @@ static unsigned getHashValueImpl(SimpleValue Val) {
     return hashCallInst(CI);
 
   // Mix in the opcode.
-  return hash_combine(
-      Inst->getOpcode(),
-      hash_combine_range(Inst->value_op_begin(), Inst->value_op_end()));
+  return hash_combine(Inst->getOpcode(),
+                      hash_combine_range(Inst->operand_values()));
 }
 
 unsigned DenseMapInfo<SimpleValue>::getHashValue(SimpleValue Val) {
@@ -608,9 +604,8 @@ unsigned DenseMapInfo<GEPValue>::getHashValue(const GEPValue &Val) {
   if (Val.ConstantOffset.has_value())
     return hash_combine(GEP->getOpcode(), GEP->getPointerOperand(),
                         Val.ConstantOffset.value());
-  return hash_combine(
-      GEP->getOpcode(),
-      hash_combine_range(GEP->value_op_begin(), GEP->value_op_end()));
+  return hash_combine(GEP->getOpcode(),
+                      hash_combine_range(GEP->operand_values()));
 }
 
 bool DenseMapInfo<GEPValue>::isEqual(const GEPValue &LHS, const GEPValue &RHS) {
diff --git a/llvm/lib/Transforms/Utils/Local.cpp b/llvm/lib/Transforms/Utils/Local.cpp
index f914d596f0bf0..414011259fcf1 100644
--- a/llvm/lib/Transforms/Utils/Local.cpp
+++ b/llvm/lib/Transforms/Utils/Local.cpp
@@ -1445,9 +1445,9 @@ EliminateDuplicatePHINodesSetBasedImpl(BasicBlock *BB,
       // Compute a hash value on the operands. Instcombine will likely have
       // sorted them, which helps expose duplicates, but we have to check all
       // the operands to be safe in case instcombine hasn't run.
-      return static_cast<unsigned>(hash_combine(
-          hash_combine_range(PN->value_op_begin(), PN->value_op_end()),
-          hash_combine_range(PN->block_begin(), PN->block_end())));
+      return static_cast<unsigned>(
+          hash_combine(hash_combine_range(PN->operand_values()),
+                       hash_combine_range(PN->blocks())));
     }
 
     static unsigned getHashValue(PHINode *PN) {
diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
index 6b5b50a26c199..724ea028bc54a 100644
--- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -2741,8 +2741,8 @@ struct CSEDenseMapInfo {
 
   static unsigned getHashValue(const Instruction *I) {
     assert(canHandle(I) && "Unknown instruction!");
-    return hash_combine(I->getOpcode(), hash_combine_range(I->value_op_begin(),
-                                                           I->value_op_end()));
+    return hash_combine(I->getOpcode(),
+                        hash_combine_range(I->operand_values()));
   }
 
   static bool isEqual(const Instruction *LHS, const Instruction *RHS) {

@llvmbot
Copy link
Member

llvmbot commented Apr 27, 2025

@llvm/pr-subscribers-vectorizers

Author: Kazu Hirata (kazutakahirata)

Changes

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

5 Files Affected:

  • (modified) llvm/include/llvm/Transforms/Scalar/GVNExpression.h (+1-1)
  • (modified) llvm/lib/ProfileData/Coverage/CoverageMapping.cpp (+1-2)
  • (modified) llvm/lib/Transforms/Scalar/EarlyCSE.cpp (+11-16)
  • (modified) llvm/lib/Transforms/Utils/Local.cpp (+3-3)
  • (modified) llvm/lib/Transforms/Vectorize/LoopVectorize.cpp (+2-2)
diff --git a/llvm/include/llvm/Transforms/Scalar/GVNExpression.h b/llvm/include/llvm/Transforms/Scalar/GVNExpression.h
index 71437953640c9..50cd6ceb9fc0d 100644
--- a/llvm/include/llvm/Transforms/Scalar/GVNExpression.h
+++ b/llvm/include/llvm/Transforms/Scalar/GVNExpression.h
@@ -221,7 +221,7 @@ class BasicExpression : public Expression {
 
   hash_code getHashValue() const override {
     return hash_combine(this->Expression::getHashValue(), ValueType,
-                        hash_combine_range(op_begin(), op_end()));
+                        hash_combine_range(operands()));
   }
 
   // Debugging support
diff --git a/llvm/lib/ProfileData/Coverage/CoverageMapping.cpp b/llvm/lib/ProfileData/Coverage/CoverageMapping.cpp
index c39585681911a..d3fe218c19a14 100644
--- a/llvm/lib/ProfileData/Coverage/CoverageMapping.cpp
+++ b/llvm/lib/ProfileData/Coverage/CoverageMapping.cpp
@@ -933,8 +933,7 @@ Error CoverageMapping::loadFunctionRecord(
   }
 
   // Don't create records for (filenames, function) pairs we've already seen.
-  auto FilenamesHash = hash_combine_range(Record.Filenames.begin(),
-                                          Record.Filenames.end());
+  auto FilenamesHash = hash_combine_range(Record.Filenames);
   if (!RecordProvenance[FilenamesHash].insert(hash_value(OrigFuncName)).second)
     return Error::success();
 
diff --git a/llvm/lib/Transforms/Scalar/EarlyCSE.cpp b/llvm/lib/Transforms/Scalar/EarlyCSE.cpp
index 3a0ae6b01a114..1e378369166c0 100644
--- a/llvm/lib/Transforms/Scalar/EarlyCSE.cpp
+++ b/llvm/lib/Transforms/Scalar/EarlyCSE.cpp
@@ -223,13 +223,11 @@ static unsigned hashCallInst(CallInst *CI) {
   // Don't CSE convergent calls in different basic blocks, because they
   // implicitly depend on the set of threads that is currently executing.
   if (CI->isConvergent()) {
-    return hash_combine(
-        CI->getOpcode(), CI->getParent(),
-        hash_combine_range(CI->value_op_begin(), CI->value_op_end()));
+    return hash_combine(CI->getOpcode(), CI->getParent(),
+                        hash_combine_range(CI->operand_values()));
   }
-  return hash_combine(
-      CI->getOpcode(),
-      hash_combine_range(CI->value_op_begin(), CI->value_op_end()));
+  return hash_combine(CI->getOpcode(),
+                      hash_combine_range(CI->operand_values()));
 }
 
 static unsigned getHashValueImpl(SimpleValue Val) {
@@ -302,12 +300,11 @@ static unsigned getHashValueImpl(SimpleValue Val) {
 
   if (const ExtractValueInst *EVI = dyn_cast<ExtractValueInst>(Inst))
     return hash_combine(EVI->getOpcode(), EVI->getOperand(0),
-                        hash_combine_range(EVI->idx_begin(), EVI->idx_end()));
+                        hash_combine_range(EVI->indices()));
 
   if (const InsertValueInst *IVI = dyn_cast<InsertValueInst>(Inst))
     return hash_combine(IVI->getOpcode(), IVI->getOperand(0),
-                        IVI->getOperand(1),
-                        hash_combine_range(IVI->idx_begin(), IVI->idx_end()));
+                        IVI->getOperand(1), hash_combine_range(IVI->indices()));
 
   assert((isa<CallInst>(Inst) || isa<ExtractElementInst>(Inst) ||
           isa<InsertElementInst>(Inst) || isa<ShuffleVectorInst>(Inst) ||
@@ -322,7 +319,7 @@ static unsigned getHashValueImpl(SimpleValue Val) {
       std::swap(LHS, RHS);
     return hash_combine(
         II->getOpcode(), LHS, RHS,
-        hash_combine_range(II->value_op_begin() + 2, II->value_op_end()));
+        hash_combine_range(drop_begin(II->operand_values(), 2)));
   }
 
   // gc.relocate is 'special' call: its second and third operands are
@@ -338,9 +335,8 @@ static unsigned getHashValueImpl(SimpleValue Val) {
     return hashCallInst(CI);
 
   // Mix in the opcode.
-  return hash_combine(
-      Inst->getOpcode(),
-      hash_combine_range(Inst->value_op_begin(), Inst->value_op_end()));
+  return hash_combine(Inst->getOpcode(),
+                      hash_combine_range(Inst->operand_values()));
 }
 
 unsigned DenseMapInfo<SimpleValue>::getHashValue(SimpleValue Val) {
@@ -608,9 +604,8 @@ unsigned DenseMapInfo<GEPValue>::getHashValue(const GEPValue &Val) {
   if (Val.ConstantOffset.has_value())
     return hash_combine(GEP->getOpcode(), GEP->getPointerOperand(),
                         Val.ConstantOffset.value());
-  return hash_combine(
-      GEP->getOpcode(),
-      hash_combine_range(GEP->value_op_begin(), GEP->value_op_end()));
+  return hash_combine(GEP->getOpcode(),
+                      hash_combine_range(GEP->operand_values()));
 }
 
 bool DenseMapInfo<GEPValue>::isEqual(const GEPValue &LHS, const GEPValue &RHS) {
diff --git a/llvm/lib/Transforms/Utils/Local.cpp b/llvm/lib/Transforms/Utils/Local.cpp
index f914d596f0bf0..414011259fcf1 100644
--- a/llvm/lib/Transforms/Utils/Local.cpp
+++ b/llvm/lib/Transforms/Utils/Local.cpp
@@ -1445,9 +1445,9 @@ EliminateDuplicatePHINodesSetBasedImpl(BasicBlock *BB,
       // Compute a hash value on the operands. Instcombine will likely have
       // sorted them, which helps expose duplicates, but we have to check all
       // the operands to be safe in case instcombine hasn't run.
-      return static_cast<unsigned>(hash_combine(
-          hash_combine_range(PN->value_op_begin(), PN->value_op_end()),
-          hash_combine_range(PN->block_begin(), PN->block_end())));
+      return static_cast<unsigned>(
+          hash_combine(hash_combine_range(PN->operand_values()),
+                       hash_combine_range(PN->blocks())));
     }
 
     static unsigned getHashValue(PHINode *PN) {
diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
index 6b5b50a26c199..724ea028bc54a 100644
--- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -2741,8 +2741,8 @@ struct CSEDenseMapInfo {
 
   static unsigned getHashValue(const Instruction *I) {
     assert(canHandle(I) && "Unknown instruction!");
-    return hash_combine(I->getOpcode(), hash_combine_range(I->value_op_begin(),
-                                                           I->value_op_end()));
+    return hash_combine(I->getOpcode(),
+                        hash_combine_range(I->operand_values()));
   }
 
   static bool isEqual(const Instruction *LHS, const Instruction *RHS) {

@kazutakahirata kazutakahirata merged commit 1f56716 into llvm:main Apr 27, 2025
15 checks passed
@kazutakahirata kazutakahirata deleted the cleanup_001_hash_combine_range_llvm branch April 27, 2025 19:36
jyli0116 pushed a commit to jyli0116/llvm-project that referenced this pull request Apr 28, 2025
IanWood1 pushed a commit to IanWood1/llvm-project that referenced this pull request May 6, 2025
IanWood1 pushed a commit to IanWood1/llvm-project that referenced this pull request May 6, 2025
IanWood1 pushed a commit to IanWood1/llvm-project that referenced this pull request May 6, 2025
Ankur-0429 pushed a commit to Ankur-0429/llvm-project that referenced this pull request May 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
llvm:transforms PGO Profile Guided Optimizations vectorizers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants