diff options
author | Nikita Popov <npopov@redhat.com> | 2023-10-09 15:36:16 +0200 |
---|---|---|
committer | Nikita Popov <npopov@redhat.com> | 2023-10-09 15:41:32 +0200 |
commit | e7b2855787cab5ccaf195b9c86985f263eb29cfe (patch) | |
tree | d5e50eb3d7b4451eeeab81cf7b19104b33c1704a /llvm/lib/IR/ConstantFold.cpp | |
parent | e01c8673ba683818d267dc03a72cf50e30befa9f (diff) | |
download | llvm-e7b2855787cab5ccaf195b9c86985f263eb29cfe.zip llvm-e7b2855787cab5ccaf195b9c86985f263eb29cfe.tar.gz llvm-e7b2855787cab5ccaf195b9c86985f263eb29cfe.tar.bz2 |
[ConstantFold] Avoid some uses of ConstantExpr::getSExt() (NFC)
Use the (internal) constant folding API instead.
Diffstat (limited to 'llvm/lib/IR/ConstantFold.cpp')
-rw-r--r-- | llvm/lib/IR/ConstantFold.cpp | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/llvm/lib/IR/ConstantFold.cpp b/llvm/lib/IR/ConstantFold.cpp index f964407..d35106a 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); } |