Skip to content

Commit f6ebd7f

Browse files
nikictomtor
authored andcommitted
[InstCombine] Export logic for common base pointer (NFC)
Make this available to other parts of InstCombine, to be used for pointer comparison optimization.
1 parent d7a4d97 commit f6ebd7f

File tree

2 files changed

+18
-16
lines changed

2 files changed

+18
-16
lines changed

llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2068,21 +2068,8 @@ Instruction *InstCombinerImpl::visitFAdd(BinaryOperator &I) {
20682068
return nullptr;
20692069
}
20702070

2071-
struct CommonBase {
2072-
/// Common base pointer.
2073-
Value *Ptr = nullptr;
2074-
/// LHS GEPs until common base.
2075-
SmallVector<GEPOperator *> LHSGEPs;
2076-
/// RHS GEPs until common base.
2077-
SmallVector<GEPOperator *> RHSGEPs;
2078-
/// LHS GEP NoWrapFlags until common base.
2079-
GEPNoWrapFlags LHSNW = GEPNoWrapFlags::all();
2080-
/// RHS GEP NoWrapFlags until common base.
2081-
GEPNoWrapFlags RHSNW = GEPNoWrapFlags::all();
2082-
};
2083-
2084-
static CommonBase computeCommonBase(Value *LHS, Value *RHS) {
2085-
CommonBase Base;
2071+
CommonPointerBase CommonPointerBase::compute(Value *LHS, Value *RHS) {
2072+
CommonPointerBase Base;
20862073

20872074
if (LHS->getType() != RHS->getType())
20882075
return Base;
@@ -2136,7 +2123,7 @@ static CommonBase computeCommonBase(Value *LHS, Value *RHS) {
21362123
/// operands to the ptrtoint instructions for the LHS/RHS of the subtract.
21372124
Value *InstCombinerImpl::OptimizePointerDifference(Value *LHS, Value *RHS,
21382125
Type *Ty, bool IsNUW) {
2139-
CommonBase Base = computeCommonBase(LHS, RHS);
2126+
CommonPointerBase Base = CommonPointerBase::compute(LHS, RHS);
21402127
if (!Base.Ptr)
21412128
return nullptr;
21422129

llvm/lib/Transforms/InstCombine/InstCombineInternal.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -862,6 +862,21 @@ class Negator final {
862862
InstCombinerImpl &IC);
863863
};
864864

865+
struct CommonPointerBase {
866+
/// Common base pointer.
867+
Value *Ptr = nullptr;
868+
/// LHS GEPs until common base.
869+
SmallVector<GEPOperator *> LHSGEPs;
870+
/// RHS GEPs until common base.
871+
SmallVector<GEPOperator *> RHSGEPs;
872+
/// LHS GEP NoWrapFlags until common base.
873+
GEPNoWrapFlags LHSNW = GEPNoWrapFlags::all();
874+
/// RHS GEP NoWrapFlags until common base.
875+
GEPNoWrapFlags RHSNW = GEPNoWrapFlags::all();
876+
877+
static CommonPointerBase compute(Value *LHS, Value *RHS);
878+
};
879+
865880
} // end namespace llvm
866881

867882
#undef DEBUG_TYPE

0 commit comments

Comments
 (0)