[llvm] 98f16df - [InstSimplify] Simplify simplifyRelativeLoad (NFCI)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 9 07:18:13 PDT 2023
Author: Nikita Popov
Date: 2023-08-09T16:18:04+02:00
New Revision: 98f16dfa136636ea8d83ed326c92c5ce3d42bd72
URL: https://github.com/llvm/llvm-project/commit/98f16dfa136636ea8d83ed326c92c5ce3d42bd72
DIFF: https://github.com/llvm/llvm-project/commit/98f16dfa136636ea8d83ed326c92c5ce3d42bd72.diff
LOG: [InstSimplify] Simplify simplifyRelativeLoad (NFCI)
Drop an unnecessary bitcast and make use of the
ConstantFoldLoadFromConstPtr API that accepts an Offset, instead
of going through a GEP expression.
Added:
Modified:
llvm/lib/Analysis/InstructionSimplify.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp
index a0fea0804d6cfb..600418a5b7debf 100644
--- a/llvm/lib/Analysis/InstructionSimplify.cpp
+++ b/llvm/lib/Analysis/InstructionSimplify.cpp
@@ -6047,21 +6047,18 @@ static Value *simplifyRelativeLoad(Constant *Ptr, Constant *Offset,
if (!IsConstantOffsetFromGlobal(Ptr, PtrSym, PtrOffset, DL))
return nullptr;
- Type *UnqualPtrTy = PointerType::getUnqual(Ptr->getContext());
Type *Int32Ty = Type::getInt32Ty(Ptr->getContext());
- Type *Int64Ty = Type::getInt64Ty(Ptr->getContext());
auto *OffsetConstInt = dyn_cast<ConstantInt>(Offset);
if (!OffsetConstInt || OffsetConstInt->getType()->getBitWidth() > 64)
return nullptr;
- uint64_t OffsetInt = OffsetConstInt->getSExtValue();
- if (OffsetInt % 4 != 0)
+ APInt OffsetInt = OffsetConstInt->getValue().sextOrTrunc(
+ DL.getIndexTypeSizeInBits(Ptr->getType()));
+ if (OffsetInt.srem(4) != 0)
return nullptr;
- Constant *C = ConstantExpr::getGetElementPtr(
- Int32Ty, Ptr, ConstantInt::get(Int64Ty, OffsetInt / 4));
- Constant *Loaded = ConstantFoldLoadFromConstPtr(C, Int32Ty, DL);
+ Constant *Loaded = ConstantFoldLoadFromConstPtr(Ptr, Int32Ty, OffsetInt, DL);
if (!Loaded)
return nullptr;
@@ -6091,7 +6088,7 @@ static Value *simplifyRelativeLoad(Constant *Ptr, Constant *Offset,
PtrSym != LoadedRHSSym || PtrOffset != LoadedRHSOffset)
return nullptr;
- return ConstantExpr::getBitCast(LoadedLHSPtr, UnqualPtrTy);
+ return LoadedLHSPtr;
}
static Value *simplifyUnaryIntrinsic(Function *F, Value *Op0,
More information about the llvm-commits
mailing list