[llvm] [InstCombine] Canonicalize `gep T* X, V / sizeof(T)` to `gep i8* X, V` (PR #76458)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Thu Dec 28 01:17:11 PST 2023
================
@@ -2470,20 +2470,18 @@ Instruction *InstCombinerImpl::visitGetElementPtrInst(GetElementPtrInst &GEP) {
uint64_t TyAllocSize = DL.getTypeAllocSize(GEPEltType).getFixedValue();
bool Matched = false;
- uint64_t C;
Value *V = nullptr;
if (TyAllocSize == 1) {
V = GEP.getOperand(1);
Matched = true;
- } else if (match(GEP.getOperand(1),
- m_AShr(m_Value(V), m_ConstantInt(C)))) {
- if (TyAllocSize == 1ULL << C)
- Matched = true;
- } else if (match(GEP.getOperand(1),
- m_SDiv(m_Value(V), m_ConstantInt(C)))) {
- if (TyAllocSize == C)
- Matched = true;
- }
+ } else if (has_single_bit(TyAllocSize) &&
+ match(GEP.getOperand(1),
+ m_Exact(m_AShr(m_Value(V), m_SpecificInt(countr_zero(
+ TyAllocSize))))))
+ Matched = true;
+ else if (match(GEP.getOperand(1),
+ m_Exact(m_SDiv(m_Value(V), m_SpecificInt(TyAllocSize)))))
+ Matched = true;
----------------
nikic wrote:
Mixing this with the ptrtoint transform seems a bit awkward. I would restructure this code so that first we have a transform that converts the sdiv/ashr into an i8 gep, and then the ptrtoint transform just has to check the i8 case, and can rely on sdiv/ashr already being converted.
https://github.com/llvm/llvm-project/pull/76458
More information about the llvm-commits
mailing list