Skip to content

Conversation

@artagnon
Copy link
Contributor

@artagnon artagnon commented Feb 3, 2025

The PointeeTy argument is not respected. To avoid misleading callers, drop the argument.

The PointeeTy argument is not respected. To avoid misleading callers,
drop the argument.
@artagnon artagnon requested a review from dtcxzyw February 3, 2025 19:46
@artagnon artagnon requested a review from nikic as a code owner February 3, 2025 19:46
@llvmbot llvmbot added llvm:instcombine Covers the InstCombine, InstSimplify and AggressiveInstCombine passes llvm:ir llvm:analysis Includes value tracking, cost tables and constant folding labels Feb 3, 2025
@llvmbot
Copy link
Member

llvmbot commented Feb 3, 2025

@llvm/pr-subscribers-llvm-analysis

@llvm/pr-subscribers-llvm-ir

Author: Ramkumar Ramachandra (artagnon)

Changes

The PointeeTy argument is not respected. To avoid misleading callers, drop the argument.


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

4 Files Affected:

  • (modified) llvm/include/llvm/IR/ConstantFold.h (+1-1)
  • (modified) llvm/lib/Analysis/InstructionSimplify.cpp (+1-1)
  • (modified) llvm/lib/IR/ConstantFold.cpp (+1-1)
  • (modified) llvm/lib/IR/Constants.cpp (+2-2)
diff --git a/llvm/include/llvm/IR/ConstantFold.h b/llvm/include/llvm/IR/ConstantFold.h
index 42043d365b2d3e..c667affd56e91d 100644
--- a/llvm/include/llvm/IR/ConstantFold.h
+++ b/llvm/include/llvm/IR/ConstantFold.h
@@ -52,7 +52,7 @@ namespace llvm {
                                           Constant *V2);
   Constant *ConstantFoldCompareInstruction(CmpInst::Predicate Predicate,
                                            Constant *C1, Constant *C2);
-  Constant *ConstantFoldGetElementPtr(Type *Ty, Constant *C,
+  Constant *ConstantFoldGetElementPtr(Constant *C,
                                       std::optional<ConstantRange> InRange,
                                       ArrayRef<Value *> Idxs);
 } // End llvm namespace
diff --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp
index d69747e30f884d..f2da230346bbee 100644
--- a/llvm/lib/Analysis/InstructionSimplify.cpp
+++ b/llvm/lib/Analysis/InstructionSimplify.cpp
@@ -5127,7 +5127,7 @@ static Value *simplifyGEPInst(Type *SrcTy, Value *Ptr,
     return nullptr;
 
   if (!ConstantExpr::isSupportedGetElementPtr(SrcTy))
-    return ConstantFoldGetElementPtr(SrcTy, cast<Constant>(Ptr), std::nullopt,
+    return ConstantFoldGetElementPtr(cast<Constant>(Ptr), std::nullopt,
                                      Indices);
 
   auto *CE =
diff --git a/llvm/lib/IR/ConstantFold.cpp b/llvm/lib/IR/ConstantFold.cpp
index b577f69eeaba0b..c78069ade42d15 100644
--- a/llvm/lib/IR/ConstantFold.cpp
+++ b/llvm/lib/IR/ConstantFold.cpp
@@ -1312,7 +1312,7 @@ Constant *llvm::ConstantFoldCompareInstruction(CmpInst::Predicate Predicate,
   return nullptr;
 }
 
-Constant *llvm::ConstantFoldGetElementPtr(Type *PointeeTy, Constant *C,
+Constant *llvm::ConstantFoldGetElementPtr(Constant *C,
                                           std::optional<ConstantRange> InRange,
                                           ArrayRef<Value *> Idxs) {
   if (Idxs.empty()) return C;
diff --git a/llvm/lib/IR/Constants.cpp b/llvm/lib/IR/Constants.cpp
index 33f4dc78c6d3f9..c94d6548364291 100644
--- a/llvm/lib/IR/Constants.cpp
+++ b/llvm/lib/IR/Constants.cpp
@@ -732,7 +732,7 @@ static bool constantIsDead(const Constant *C, bool RemoveDeadUsers) {
     ReplaceableMetadataImpl::SalvageDebugInfo(*C);
     const_cast<Constant *>(C)->destroyConstant();
   }
-  
+
   return true;
 }
 
@@ -2509,7 +2509,7 @@ Constant *ConstantExpr::getGetElementPtr(Type *Ty, Constant *C,
   assert(Ty && "Must specify element type");
   assert(isSupportedGetElementPtr(Ty) && "Element type is unsupported!");
 
-  if (Constant *FC = ConstantFoldGetElementPtr(Ty, C, InRange, Idxs))
+  if (Constant *FC = ConstantFoldGetElementPtr(C, InRange, Idxs))
     return FC; // Fold a few common cases.
 
   assert(GetElementPtrInst::getIndexedType(Ty, Idxs) && "GEP indices invalid!");

Copy link
Contributor

@nikic nikic 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 this parameter should be dropped, even if we currently happen to not have any folds that require it.

@artagnon artagnon closed this Feb 3, 2025
@artagnon artagnon deleted the constfold-gep-nfc branch February 3, 2025 19:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

llvm:analysis Includes value tracking, cost tables and constant folding llvm:instcombine Covers the InstCombine, InstSimplify and AggressiveInstCombine passes llvm:ir

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants