[llvm] e7b2855 - [ConstantFold] Avoid some uses of ConstantExpr::getSExt() (NFC)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Mon Oct 9 06:42:10 PDT 2023
Author: Nikita Popov
Date: 2023-10-09T15:41:32+02:00
New Revision: e7b2855787cab5ccaf195b9c86985f263eb29cfe
URL: https://github.com/llvm/llvm-project/commit/e7b2855787cab5ccaf195b9c86985f263eb29cfe
DIFF: https://github.com/llvm/llvm-project/commit/e7b2855787cab5ccaf195b9c86985f263eb29cfe.diff
LOG: [ConstantFold] Avoid some uses of ConstantExpr::getSExt() (NFC)
Use the (internal) constant folding API instead.
Added:
Modified:
llvm/lib/IR/ConstantFold.cpp
Removed:
################################################################################
diff --git a/llvm/lib/IR/ConstantFold.cpp b/llvm/lib/IR/ConstantFold.cpp
index f9644079f2d2b36..d35106ae02b0dd0 100644
--- a/llvm/lib/IR/ConstantFold.cpp
+++ b/llvm/lib/IR/ConstantFold.cpp
@@ -1945,8 +1945,13 @@ static Constant *foldGEPOfGEP(GEPOperator *GEP, Type *PointeeTy, bool InBounds,
Type *CommonTy =
Type::getIntNTy(LastIdxTy->getContext(), CommonExtendedWidth);
- Idx0 = ConstantExpr::getSExtOrBitCast(Idx0, CommonTy);
- LastIdx = ConstantExpr::getSExtOrBitCast(LastIdx, CommonTy);
+ if (Idx0->getType() != CommonTy)
+ Idx0 = ConstantFoldCastInstruction(Instruction::SExt, Idx0, CommonTy);
+ if (LastIdx->getType() != CommonTy)
+ LastIdx =
+ ConstantFoldCastInstruction(Instruction::SExt, LastIdx, CommonTy);
+ if (!Idx0 || !LastIdx)
+ return nullptr;
}
NewIndices.push_back(ConstantExpr::get(Instruction::Add, Idx0, LastIdx));
@@ -2164,11 +2169,13 @@ Constant *llvm::ConstantFoldGetElementPtr(Type *PointeeTy, Constant *C,
: cast<FixedVectorType>(CurrIdx->getType())->getNumElements());
if (!PrevIdx->getType()->isIntOrIntVectorTy(CommonExtendedWidth))
- PrevIdx = ConstantExpr::getSExt(PrevIdx, ExtendedTy);
+ PrevIdx =
+ ConstantFoldCastInstruction(Instruction::SExt, PrevIdx, ExtendedTy);
if (!Div->getType()->isIntOrIntVectorTy(CommonExtendedWidth))
- Div = ConstantExpr::getSExt(Div, ExtendedTy);
+ Div = ConstantFoldCastInstruction(Instruction::SExt, Div, ExtendedTy);
+ assert(PrevIdx && Div && "Should have folded");
NewIdxs[i - 1] = ConstantExpr::getAdd(PrevIdx, Div);
}
More information about the llvm-commits
mailing list