aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/IR/ConstantFold.cpp
diff options
context:
space:
mode:
authorPaul Walker <paul.walker@arm.com>2024-12-16 11:37:50 +0000
committerGitHub <noreply@github.com>2024-12-16 11:37:50 +0000
commit02328e0465c256293950542f1a85eb55bcbc9d45 (patch)
tree7794e2b8707458a8dafb2eaad889ed58f0493995 /llvm/lib/IR/ConstantFold.cpp
parent3ad2399148953837622d78d18ae9fd0db6ad0557 (diff)
downloadllvm-02328e0465c256293950542f1a85eb55bcbc9d45.zip
llvm-02328e0465c256293950542f1a85eb55bcbc9d45.tar.gz
llvm-02328e0465c256293950542f1a85eb55bcbc9d45.tar.bz2
[LLVM][ConstantFold] Remove remaining uses of ConstantInt/FP::get(LLVMContext... (#119912)
This extends the constant folds to support vector ConstantInt/FP.
Diffstat (limited to 'llvm/lib/IR/ConstantFold.cpp')
-rw-r--r--llvm/lib/IR/ConstantFold.cpp29
1 files changed, 14 insertions, 15 deletions
diff --git a/llvm/lib/IR/ConstantFold.cpp b/llvm/lib/IR/ConstantFold.cpp
index 3a04f81..b577f69 100644
--- a/llvm/lib/IR/ConstantFold.cpp
+++ b/llvm/lib/IR/ConstantFold.cpp
@@ -198,9 +198,9 @@ Constant *llvm::ConstantFoldCastInstruction(unsigned opc, Constant *V,
if (ConstantFP *FPC = dyn_cast<ConstantFP>(V)) {
bool ignored;
APFloat Val = FPC->getValueAPF();
- Val.convert(DestTy->getFltSemantics(), APFloat::rmNearestTiesToEven,
- &ignored);
- return ConstantFP::get(V->getContext(), Val);
+ Val.convert(DestTy->getScalarType()->getFltSemantics(),
+ APFloat::rmNearestTiesToEven, &ignored);
+ return ConstantFP::get(DestTy, Val);
}
return nullptr; // Can't fold.
case Instruction::FPToUI:
@@ -208,26 +208,25 @@ Constant *llvm::ConstantFoldCastInstruction(unsigned opc, Constant *V,
if (ConstantFP *FPC = dyn_cast<ConstantFP>(V)) {
const APFloat &V = FPC->getValueAPF();
bool ignored;
- uint32_t DestBitWidth = cast<IntegerType>(DestTy)->getBitWidth();
- APSInt IntVal(DestBitWidth, opc == Instruction::FPToUI);
+ APSInt IntVal(DestTy->getScalarSizeInBits(), opc == Instruction::FPToUI);
if (APFloat::opInvalidOp ==
V.convertToInteger(IntVal, APFloat::rmTowardZero, &ignored)) {
// Undefined behavior invoked - the destination type can't represent
// the input constant.
return PoisonValue::get(DestTy);
}
- return ConstantInt::get(FPC->getContext(), IntVal);
+ return ConstantInt::get(DestTy, IntVal);
}
return nullptr; // Can't fold.
case Instruction::UIToFP:
case Instruction::SIToFP:
if (ConstantInt *CI = dyn_cast<ConstantInt>(V)) {
const APInt &api = CI->getValue();
- APFloat apf(DestTy->getFltSemantics(),
- APInt::getZero(DestTy->getPrimitiveSizeInBits()));
+ APFloat apf(DestTy->getScalarType()->getFltSemantics(),
+ APInt::getZero(DestTy->getScalarSizeInBits()));
apf.convertFromAPInt(api, opc==Instruction::SIToFP,
APFloat::rmNearestTiesToEven);
- return ConstantFP::get(V->getContext(), apf);
+ return ConstantFP::get(DestTy, apf);
}
return nullptr;
case Instruction::ZExt:
@@ -573,7 +572,7 @@ Constant *llvm::ConstantFoldUnaryInstruction(unsigned Opcode, Constant *C) {
default:
break;
case Instruction::FNeg:
- return ConstantFP::get(C->getContext(), neg(CV));
+ return ConstantFP::get(C->getType(), neg(CV));
}
} else if (auto *VTy = dyn_cast<VectorType>(C->getType())) {
// Fast path for splatted constants.
@@ -857,19 +856,19 @@ Constant *llvm::ConstantFoldBinaryInstruction(unsigned Opcode, Constant *C1,
break;
case Instruction::FAdd:
(void)C3V.add(C2V, APFloat::rmNearestTiesToEven);
- return ConstantFP::get(C1->getContext(), C3V);
+ return ConstantFP::get(C1->getType(), C3V);
case Instruction::FSub:
(void)C3V.subtract(C2V, APFloat::rmNearestTiesToEven);
- return ConstantFP::get(C1->getContext(), C3V);
+ return ConstantFP::get(C1->getType(), C3V);
case Instruction::FMul:
(void)C3V.multiply(C2V, APFloat::rmNearestTiesToEven);
- return ConstantFP::get(C1->getContext(), C3V);
+ return ConstantFP::get(C1->getType(), C3V);
case Instruction::FDiv:
(void)C3V.divide(C2V, APFloat::rmNearestTiesToEven);
- return ConstantFP::get(C1->getContext(), C3V);
+ return ConstantFP::get(C1->getType(), C3V);
case Instruction::FRem:
(void)C3V.mod(C2V);
- return ConstantFP::get(C1->getContext(), C3V);
+ return ConstantFP::get(C1->getType(), C3V);
}
}
}