-
Notifications
You must be signed in to change notification settings - Fork 12k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[IR] Remove FP cast constant expressions #71408
Conversation
Remove support for the fptrunc, fpext, fptoui, fptosi, uitofp and sitofp constant expressions. All places cerating them have been removed beforehand, so this just removes the APIs and uses of these constant expressions in tests. With this, the only remaining FP operation that still has constant expression support is fcmp. This is part of https://discourse.llvm.org/t/rfc-remove-most-constant-expressions/63179.
@llvm/pr-subscribers-llvm-globalisel @llvm/pr-subscribers-backend-amdgpu Author: Nikita Popov (nikic) ChangesRemove support for the fptrunc, fpext, fptoui, fptosi, uitofp and sitofp constant expressions. All places cerating them have been removed beforehand, so this just removes the APIs and uses of these constant expressions in tests. With this, the only remaining FP operation that still has constant expression support is fcmp. This is part of https://discourse.llvm.org/t/rfc-remove-most-constant-expressions/63179. Patch is 38.82 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/71408.diff 20 Files Affected:
diff --git a/llvm/bindings/ocaml/llvm/llvm.ml b/llvm/bindings/ocaml/llvm/llvm.ml
index cabf32cae376f22..581d832430074d6 100644
--- a/llvm/bindings/ocaml/llvm/llvm.ml
+++ b/llvm/bindings/ocaml/llvm/llvm.ml
@@ -661,12 +661,6 @@ external const_gep : lltype -> llvalue -> llvalue array -> llvalue
external const_in_bounds_gep : lltype -> llvalue -> llvalue array -> llvalue
= "llvm_const_in_bounds_gep"
external const_trunc : llvalue -> lltype -> llvalue = "llvm_const_trunc"
-external const_fptrunc : llvalue -> lltype -> llvalue = "llvm_const_fptrunc"
-external const_fpext : llvalue -> lltype -> llvalue = "llvm_const_fpext"
-external const_uitofp : llvalue -> lltype -> llvalue = "llvm_const_uitofp"
-external const_sitofp : llvalue -> lltype -> llvalue = "llvm_const_sitofp"
-external const_fptoui : llvalue -> lltype -> llvalue = "llvm_const_fptoui"
-external const_fptosi : llvalue -> lltype -> llvalue = "llvm_const_fptosi"
external const_ptrtoint : llvalue -> lltype -> llvalue = "llvm_const_ptrtoint"
external const_inttoptr : llvalue -> lltype -> llvalue = "llvm_const_inttoptr"
external const_bitcast : llvalue -> lltype -> llvalue = "llvm_const_bitcast"
@@ -674,7 +668,6 @@ external const_trunc_or_bitcast : llvalue -> lltype -> llvalue
= "llvm_const_trunc_or_bitcast"
external const_pointercast : llvalue -> lltype -> llvalue
= "llvm_const_pointercast"
-external const_fpcast : llvalue -> lltype -> llvalue = "llvm_const_fpcast"
external const_extractelement : llvalue -> llvalue -> llvalue
= "llvm_const_extractelement"
external const_insertelement : llvalue -> llvalue -> llvalue -> llvalue
diff --git a/llvm/bindings/ocaml/llvm/llvm.mli b/llvm/bindings/ocaml/llvm/llvm.mli
index ee691ca83624455..f9aab89e4bddfbd 100644
--- a/llvm/bindings/ocaml/llvm/llvm.mli
+++ b/llvm/bindings/ocaml/llvm/llvm.mli
@@ -1171,36 +1171,6 @@ val const_in_bounds_gep : lltype -> llvalue -> llvalue array -> llvalue
See the method [llvm::ConstantExpr::getTrunc]. *)
val const_trunc : llvalue -> lltype -> llvalue
-(** [const_fptrunc c ty] returns the constant truncation of floating point
- constant [c] to the smaller floating point type [ty].
- See the method [llvm::ConstantExpr::getFPTrunc]. *)
-val const_fptrunc : llvalue -> lltype -> llvalue
-
-(** [const_fpext c ty] returns the constant extension of floating point constant
- [c] to the larger floating point type [ty].
- See the method [llvm::ConstantExpr::getFPExt]. *)
-val const_fpext : llvalue -> lltype -> llvalue
-
-(** [const_uitofp c ty] returns the constant floating point conversion of
- unsigned integer constant [c] to the floating point type [ty].
- See the method [llvm::ConstantExpr::getUIToFP]. *)
-val const_uitofp : llvalue -> lltype -> llvalue
-
-(** [const_sitofp c ty] returns the constant floating point conversion of
- signed integer constant [c] to the floating point type [ty].
- See the method [llvm::ConstantExpr::getSIToFP]. *)
-val const_sitofp : llvalue -> lltype -> llvalue
-
-(** [const_fptoui c ty] returns the constant unsigned integer conversion of
- floating point constant [c] to integer type [ty].
- See the method [llvm::ConstantExpr::getFPToUI]. *)
-val const_fptoui : llvalue -> lltype -> llvalue
-
-(** [const_fptoui c ty] returns the constant unsigned integer conversion of
- floating point constant [c] to integer type [ty].
- See the method [llvm::ConstantExpr::getFPToSI]. *)
-val const_fptosi : llvalue -> lltype -> llvalue
-
(** [const_ptrtoint c ty] returns the constant integer conversion of
pointer constant [c] to integer type [ty].
See the method [llvm::ConstantExpr::getPtrToInt]. *)
@@ -1226,11 +1196,6 @@ val const_trunc_or_bitcast : llvalue -> lltype -> llvalue
See the method [llvm::ConstantExpr::getPointerCast]. *)
val const_pointercast : llvalue -> lltype -> llvalue
-(** [const_fpcast c ty] returns a constant fpext, bitcast, or fptrunc for fp ->
- fp casts of constant [c] to type [ty].
- See the method [llvm::ConstantExpr::getFPCast]. *)
-val const_fpcast : llvalue -> lltype -> llvalue
-
(** [const_extractelement vec i] returns the constant [i]th element of
constant vector [vec]. [i] must be a constant [i32] value unsigned less than
the size of the vector.
diff --git a/llvm/bindings/ocaml/llvm/llvm_ocaml.c b/llvm/bindings/ocaml/llvm/llvm_ocaml.c
index 7c5df6643d21a8a..4c4c49027206c05 100644
--- a/llvm/bindings/ocaml/llvm/llvm_ocaml.c
+++ b/llvm/bindings/ocaml/llvm/llvm_ocaml.c
@@ -1271,42 +1271,6 @@ value llvm_const_trunc(value CV, value T) {
return to_val(Value);
}
-/* llvalue -> lltype -> llvalue */
-value llvm_const_fptrunc(value CV, value T) {
- LLVMValueRef Value = LLVMConstFPTrunc(Value_val(CV), Type_val(T));
- return to_val(Value);
-}
-
-/* llvalue -> lltype -> llvalue */
-value llvm_const_fpext(value CV, value T) {
- LLVMValueRef Value = LLVMConstFPExt(Value_val(CV), Type_val(T));
- return to_val(Value);
-}
-
-/* llvalue -> lltype -> llvalue */
-value llvm_const_uitofp(value CV, value T) {
- LLVMValueRef Value = LLVMConstUIToFP(Value_val(CV), Type_val(T));
- return to_val(Value);
-}
-
-/* llvalue -> lltype -> llvalue */
-value llvm_const_sitofp(value CV, value T) {
- LLVMValueRef Value = LLVMConstSIToFP(Value_val(CV), Type_val(T));
- return to_val(Value);
-}
-
-/* llvalue -> lltype -> llvalue */
-value llvm_const_fptoui(value CV, value T) {
- LLVMValueRef Value = LLVMConstFPToUI(Value_val(CV), Type_val(T));
- return to_val(Value);
-}
-
-/* llvalue -> lltype -> llvalue */
-value llvm_const_fptosi(value CV, value T) {
- LLVMValueRef Value = LLVMConstFPToSI(Value_val(CV), Type_val(T));
- return to_val(Value);
-}
-
/* llvalue -> lltype -> llvalue */
value llvm_const_ptrtoint(value CV, value T) {
LLVMValueRef Value = LLVMConstPtrToInt(Value_val(CV), Type_val(T));
@@ -1337,12 +1301,6 @@ value llvm_const_pointercast(value CV, value T) {
return to_val(Value);
}
-/* llvalue -> lltype -> llvalue */
-value llvm_const_fpcast(value CV, value T) {
- LLVMValueRef Value = LLVMConstFPCast(Value_val(CV), Type_val(T));
- return to_val(Value);
-}
-
/* llvalue -> llvalue -> llvalue */
value llvm_const_extractelement(value V, value I) {
LLVMValueRef Value = LLVMConstExtractElement(Value_val(V), Value_val(I));
diff --git a/llvm/docs/LangRef.rst b/llvm/docs/LangRef.rst
index 106dfab7409fa11..5d74e13c789ddd6 100644
--- a/llvm/docs/LangRef.rst
+++ b/llvm/docs/LangRef.rst
@@ -4657,38 +4657,6 @@ The following is the syntax for constant expressions:
``trunc (CST to TYPE)``
Perform the :ref:`trunc operation <i_trunc>` on constants.
-``fptrunc (CST to TYPE)``
- Truncate a floating-point constant to another floating-point type.
- The size of CST must be larger than the size of TYPE. Both types
- must be floating-point.
-``fpext (CST to TYPE)``
- Floating-point extend a constant to another type. The size of CST
- must be smaller or equal to the size of TYPE. Both types must be
- floating-point.
-``fptoui (CST to TYPE)``
- Convert a floating-point constant to the corresponding unsigned
- integer constant. TYPE must be a scalar or vector integer type. CST
- must be of scalar or vector floating-point type. Both CST and TYPE
- must be scalars, or vectors of the same number of elements. If the
- value won't fit in the integer type, the result is a
- :ref:`poison value <poisonvalues>`.
-``fptosi (CST to TYPE)``
- Convert a floating-point constant to the corresponding signed
- integer constant. TYPE must be a scalar or vector integer type. CST
- must be of scalar or vector floating-point type. Both CST and TYPE
- must be scalars, or vectors of the same number of elements. If the
- value won't fit in the integer type, the result is a
- :ref:`poison value <poisonvalues>`.
-``uitofp (CST to TYPE)``
- Convert an unsigned integer constant to the corresponding
- floating-point constant. TYPE must be a scalar or vector floating-point
- type. CST must be of scalar or vector integer type. Both CST and TYPE must
- be scalars, or vectors of the same number of elements.
-``sitofp (CST to TYPE)``
- Convert a signed integer constant to the corresponding floating-point
- constant. TYPE must be a scalar or vector floating-point type.
- CST must be of scalar or vector integer type. Both CST and TYPE must
- be scalars, or vectors of the same number of elements.
``ptrtoint (CST to TYPE)``
Perform the :ref:`ptrtoint operation <i_ptrtoint>` on constants.
``inttoptr (CST to TYPE)``
diff --git a/llvm/docs/ReleaseNotes.rst b/llvm/docs/ReleaseNotes.rst
index 23b54e6a37a7451..2544aebaf2a22ef 100644
--- a/llvm/docs/ReleaseNotes.rst
+++ b/llvm/docs/ReleaseNotes.rst
@@ -59,6 +59,12 @@ Changes to the LLVM IR
* ``or``
* ``zext``
* ``sext``
+ * ``fptrunc``
+ * ``fpext``
+ * ``fptoui``
+ * ``fptosi``
+ * ``uitofp``
+ * ``sitofp``
* Added `llvm.exp10` intrinsic.
@@ -173,6 +179,13 @@ Changes to the C API
* ``LLVMConstZExtOrBitCast``
* ``LLVMConstSExtOrBitCast``
* ``LLVMConstIntCast``
+ * ``LLVMConstFPTrunc``
+ * ``LLVMConstFPExt``
+ * ``LLVMConstFPToUI``
+ * ``LLVMConstFPToSI``
+ * ``LLVMConstUIToFP``
+ * ``LLVMConstSIToFP``
+ * ``LLVMConstFPCast``
* Added ``LLVMCreateTargetMachineWithOptions``, along with helper functions for
an opaque option structure, as an alternative to ``LLVMCreateTargetMachine``.
diff --git a/llvm/include/llvm-c/Core.h b/llvm/include/llvm-c/Core.h
index 4fc88b2b64eacea..ceeb74bd4e6fa99 100644
--- a/llvm/include/llvm-c/Core.h
+++ b/llvm/include/llvm-c/Core.h
@@ -2290,12 +2290,6 @@ LLVMValueRef LLVMConstInBoundsGEP2(LLVMTypeRef Ty, LLVMValueRef ConstantVal,
LLVMValueRef *ConstantIndices,
unsigned NumIndices);
LLVMValueRef LLVMConstTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
-LLVMValueRef LLVMConstFPTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
-LLVMValueRef LLVMConstFPExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
-LLVMValueRef LLVMConstUIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
-LLVMValueRef LLVMConstSIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
-LLVMValueRef LLVMConstFPToUI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
-LLVMValueRef LLVMConstFPToSI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
LLVMValueRef LLVMConstPtrToInt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
LLVMValueRef LLVMConstIntToPtr(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
LLVMValueRef LLVMConstBitCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
@@ -2304,7 +2298,6 @@ LLVMValueRef LLVMConstTruncOrBitCast(LLVMValueRef ConstantVal,
LLVMTypeRef ToType);
LLVMValueRef LLVMConstPointerCast(LLVMValueRef ConstantVal,
LLVMTypeRef ToType);
-LLVMValueRef LLVMConstFPCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
LLVMValueRef LLVMConstExtractElement(LLVMValueRef VectorConstant,
LLVMValueRef IndexConstant);
LLVMValueRef LLVMConstInsertElement(LLVMValueRef VectorConstant,
diff --git a/llvm/include/llvm/IR/Constants.h b/llvm/include/llvm/IR/Constants.h
index 43744ba8a617812..cf3812a79f028fb 100644
--- a/llvm/include/llvm/IR/Constants.h
+++ b/llvm/include/llvm/IR/Constants.h
@@ -1041,14 +1041,6 @@ class ConstantExpr : public Constant {
static Constant *getLShr(Constant *C1, Constant *C2, bool isExact = false);
static Constant *getAShr(Constant *C1, Constant *C2, bool isExact = false);
static Constant *getTrunc(Constant *C, Type *Ty, bool OnlyIfReduced = false);
- static Constant *getFPTrunc(Constant *C, Type *Ty,
- bool OnlyIfReduced = false);
- static Constant *getFPExtend(Constant *C, Type *Ty,
- bool OnlyIfReduced = false);
- static Constant *getUIToFP(Constant *C, Type *Ty, bool OnlyIfReduced = false);
- static Constant *getSIToFP(Constant *C, Type *Ty, bool OnlyIfReduced = false);
- static Constant *getFPToUI(Constant *C, Type *Ty, bool OnlyIfReduced = false);
- static Constant *getFPToSI(Constant *C, Type *Ty, bool OnlyIfReduced = false);
static Constant *getPtrToInt(Constant *C, Type *Ty,
bool OnlyIfReduced = false);
static Constant *getIntToPtr(Constant *C, Type *Ty,
@@ -1158,11 +1150,6 @@ class ConstantExpr : public Constant {
Type *Ty ///< The type to bitcast or addrspacecast C to
);
- /// Create a FPExt, Bitcast or FPTrunc for fp -> fp casts
- static Constant *getFPCast(Constant *C, ///< The integer constant to be casted
- Type *Ty ///< The integer type to cast to
- );
-
/// Return true if this is a convert constant expression
bool isCast() const;
diff --git a/llvm/include/llvm/IR/PatternMatch.h b/llvm/include/llvm/IR/PatternMatch.h
index 2551e81b62b6d0d..f709a5ac52a4125 100644
--- a/llvm/include/llvm/IR/PatternMatch.h
+++ b/llvm/include/llvm/IR/PatternMatch.h
@@ -1697,34 +1697,34 @@ m_ZExtOrSExtOrSelf(const OpTy &Op) {
}
template <typename OpTy>
-inline CastOperator_match<OpTy, Instruction::UIToFP> m_UIToFP(const OpTy &Op) {
- return CastOperator_match<OpTy, Instruction::UIToFP>(Op);
+inline CastInst_match<OpTy, Instruction::UIToFP> m_UIToFP(const OpTy &Op) {
+ return CastInst_match<OpTy, Instruction::UIToFP>(Op);
}
template <typename OpTy>
-inline CastOperator_match<OpTy, Instruction::SIToFP> m_SIToFP(const OpTy &Op) {
- return CastOperator_match<OpTy, Instruction::SIToFP>(Op);
+inline CastInst_match<OpTy, Instruction::SIToFP> m_SIToFP(const OpTy &Op) {
+ return CastInst_match<OpTy, Instruction::SIToFP>(Op);
}
template <typename OpTy>
-inline CastOperator_match<OpTy, Instruction::FPToUI> m_FPToUI(const OpTy &Op) {
- return CastOperator_match<OpTy, Instruction::FPToUI>(Op);
+inline CastInst_match<OpTy, Instruction::FPToUI> m_FPToUI(const OpTy &Op) {
+ return CastInst_match<OpTy, Instruction::FPToUI>(Op);
}
template <typename OpTy>
-inline CastOperator_match<OpTy, Instruction::FPToSI> m_FPToSI(const OpTy &Op) {
- return CastOperator_match<OpTy, Instruction::FPToSI>(Op);
+inline CastInst_match<OpTy, Instruction::FPToSI> m_FPToSI(const OpTy &Op) {
+ return CastInst_match<OpTy, Instruction::FPToSI>(Op);
}
template <typename OpTy>
-inline CastOperator_match<OpTy, Instruction::FPTrunc>
+inline CastInst_match<OpTy, Instruction::FPTrunc>
m_FPTrunc(const OpTy &Op) {
- return CastOperator_match<OpTy, Instruction::FPTrunc>(Op);
+ return CastInst_match<OpTy, Instruction::FPTrunc>(Op);
}
template <typename OpTy>
-inline CastOperator_match<OpTy, Instruction::FPExt> m_FPExt(const OpTy &Op) {
- return CastOperator_match<OpTy, Instruction::FPExt>(Op);
+inline CastInst_match<OpTy, Instruction::FPExt> m_FPExt(const OpTy &Op) {
+ return CastInst_match<OpTy, Instruction::FPExt>(Op);
}
//===----------------------------------------------------------------------===//
diff --git a/llvm/lib/AsmParser/LLParser.cpp b/llvm/lib/AsmParser/LLParser.cpp
index d3abd16204a4534..95fe5ede28a8864 100644
--- a/llvm/lib/AsmParser/LLParser.cpp
+++ b/llvm/lib/AsmParser/LLParser.cpp
@@ -3805,14 +3805,8 @@ bool LLParser::parseValID(ValID &ID, PerFunctionState *PFS, Type *ExpectedTy) {
}
case lltok::kw_trunc:
- case lltok::kw_fptrunc:
- case lltok::kw_fpext:
case lltok::kw_bitcast:
case lltok::kw_addrspacecast:
- case lltok::kw_uitofp:
- case lltok::kw_sitofp:
- case lltok::kw_fptoui:
- case lltok::kw_fptosi:
case lltok::kw_inttoptr:
case lltok::kw_ptrtoint: {
unsigned Opc = Lex.getUIntVal();
@@ -3868,6 +3862,18 @@ bool LLParser::parseValID(ValID &ID, PerFunctionState *PFS, Type *ExpectedTy) {
return error(ID.Loc, "zext constexprs are no longer supported");
case lltok::kw_sext:
return error(ID.Loc, "sext constexprs are no longer supported");
+ case lltok::kw_fptrunc:
+ return error(ID.Loc, "fptrunc constexprs are no longer supported");
+ case lltok::kw_fpext:
+ return error(ID.Loc, "fpext constexprs are no longer supported");
+ case lltok::kw_uitofp:
+ return error(ID.Loc, "uitofp constexprs are no longer supported");
+ case lltok::kw_sitofp:
+ return error(ID.Loc, "sitofp constexprs are no longer supported");
+ case lltok::kw_fptoui:
+ return error(ID.Loc, "fptoui constexprs are no longer supported");
+ case lltok::kw_fptosi:
+ return error(ID.Loc, "fptosi constexprs are no longer supported");
case lltok::kw_icmp:
case lltok::kw_fcmp: {
unsigned PredVal, Opc = Lex.getUIntVal();
diff --git a/llvm/lib/IR/Constants.cpp b/llvm/lib/IR/Constants.cpp
index 16072d2efc95bfd..4e480691558f043 100644
--- a/llvm/lib/IR/Constants.cpp
+++ b/llvm/lib/IR/Constants.cpp
@@ -1968,18 +1968,6 @@ Constant *ConstantExpr::getCast(unsigned oc, Constant *C, Type *Ty,
llvm_unreachable("Invalid cast opcode");
case Instruction::Trunc:
return getTrunc(C, Ty, OnlyIfReduced);
- case Instruction::FPTrunc:
- return getFPTrunc(C, Ty, OnlyIfReduced);
- case Instruction::FPExt:
- return getFPExtend(C, Ty, OnlyIfReduced);
- case Instruction::UIToFP:
- return getUIToFP(C, Ty, OnlyIfReduced);
- case Instruction::SIToFP:
- return getSIToFP(C, Ty, OnlyIfReduced);
- case Instruction::FPToUI:
- return getFPToUI(C, Ty, OnlyIfReduced);
- case Instruction::FPToSI:
- return getFPToSI(C, Ty, OnlyIfReduced);
case Instruction::PtrToInt:
return getPtrToInt(C, Ty, OnlyIfReduced);
case Instruction::IntToPtr:
@@ -2023,18 +2011,6 @@ Constant *ConstantExpr::getPointerBitCastOrAddrSpaceCast(Constant *S,
return getBitCast(S, Ty);
}
-Constant *ConstantExpr::getFPCast(Constant *C, Type *Ty) {
- assert(C->getType()->isFPOrFPVectorTy() && Ty->isFPOrFPVectorTy() &&
- "Invalid cast");
- unsigned SrcBits = C->getType()->getScalarSizeInBits();
- unsigned DstBits = Ty->getScalarSizeInBits();
- if (SrcBits == DstBits)
- return C; // Avoid a useless cast
- Instruction::CastOps opcode =
- (SrcBits > DstBits ? Instruction::FPTrunc : Instruction::FPExt);
- return getCast(opcode, C, Ty);
-}
-
Constant *ConstantExpr::getTrunc(Constant *C, Type *Ty, bool OnlyIfReduced) {
#ifndef NDEBUG
bool fromVec = isa<VectorType>(C->getType());
@@ -2049,74 +2025,6 @@ Constant *ConstantExpr::getTrunc(Constant *C, Type *Ty, bool OnlyIfReduced) {
return getFoldedCast(Instruction::Trunc, C, Ty, OnlyIfReduced);
}
-Constant *ConstantExpr::getFPTrunc(Constant *C, Type *Ty, bool OnlyIfReduced) {
-#ifndef NDEBUG
- bool fromVec = isa<VectorType>(C->getType());
- bool toVec = isa<VectorType>(Ty);
-#endif
- assert((fromVec == toVec) && "Cannot convert from scalar to/from vector");
- assert(C->getType()->isFPOrFPVectorTy() && Ty->isFPOrFPVectorTy() &&
- C->getType()->getScalarSizeInBits() > Ty->getScalarSizeInBits()&&
- "This is an illegal floating point truncation!");
- return getFoldedCast(Instruction::FPTrunc, C, Ty, OnlyIfReduced);
-}
-
-Constant *ConstantExpr::getFPExtend(Constant *C, Type *Ty, bool OnlyIfReduced) {
-#ifndef NDEBUG
- bool fromVec = isa<VectorType>(C->getType());
- bool toVec = isa<VectorType>(Ty);
-#endif
- assert((fromVec == toVec) && "Cannot convert from scalar to/from vector");
- assert(C->getType()->isFPOrFPVectorTy() && Ty->isFPOrFPVectorTy() &&
- C->getType()->getScalarSizeInBits() < Ty->getScalarSizeInBits()&&
- "This is an illegal floating point extension!");
- return getFoldedCast(Instruction::FPExt, C, Ty, OnlyIfReduced);
-}
-
-Constant *ConstantExpr::getUIToFP(Constant *C, Type *Ty, bool OnlyIfReduced) {
-#ifndef NDEBUG
- bool fromVec = isa<VectorType>(C->getType());
- bool toVec = isa<VectorType>(Ty);
-#endif
- assert((fromVec == toVec) && "Cannot convert from scalar to/from vector");
- assert(C->getType()->isIntOrIntVectorTy() && Ty->isFPOrFPVectorTy() &&
- "This is an illegal uint to floating point cast!");
- return getFoldedCast(Instruction::UIToFP, C, Ty, OnlyIfReduced);
-}
-
-Constant *ConstantExpr::getSIToFP(Constant *C, Type *Ty, bool OnlyIfReduced) {
-#ifndef NDEBUG
- bool fromVec = isa<VectorType>(C->getType());
- bool toVec = isa<VectorType>(Ty);
-#endif
- assert((fromVec == toVec) && "Cannot convert from scalar to/from vector");
- assert(C->getType()->isIntOrIntVectorTy() && Ty->i...
[truncated]
|
@llvm/pr-subscribers-llvm-ir Author: Nikita Popov (nikic) ChangesRemove support for the fptrunc, fpext, fptoui, fptosi, uitofp and sitofp constant expressions. All places cerating them have been removed beforehand, so this just removes the APIs and uses of these constant expressions in tests. With this, the only remaining FP operation that still has constant expression support is fcmp. This is part of https://discourse.llvm.org/t/rfc-remove-most-constant-expressions/63179. Patch is 38.82 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/71408.diff 20 Files Affected:
diff --git a/llvm/bindings/ocaml/llvm/llvm.ml b/llvm/bindings/ocaml/llvm/llvm.ml
index cabf32cae376f22..581d832430074d6 100644
--- a/llvm/bindings/ocaml/llvm/llvm.ml
+++ b/llvm/bindings/ocaml/llvm/llvm.ml
@@ -661,12 +661,6 @@ external const_gep : lltype -> llvalue -> llvalue array -> llvalue
external const_in_bounds_gep : lltype -> llvalue -> llvalue array -> llvalue
= "llvm_const_in_bounds_gep"
external const_trunc : llvalue -> lltype -> llvalue = "llvm_const_trunc"
-external const_fptrunc : llvalue -> lltype -> llvalue = "llvm_const_fptrunc"
-external const_fpext : llvalue -> lltype -> llvalue = "llvm_const_fpext"
-external const_uitofp : llvalue -> lltype -> llvalue = "llvm_const_uitofp"
-external const_sitofp : llvalue -> lltype -> llvalue = "llvm_const_sitofp"
-external const_fptoui : llvalue -> lltype -> llvalue = "llvm_const_fptoui"
-external const_fptosi : llvalue -> lltype -> llvalue = "llvm_const_fptosi"
external const_ptrtoint : llvalue -> lltype -> llvalue = "llvm_const_ptrtoint"
external const_inttoptr : llvalue -> lltype -> llvalue = "llvm_const_inttoptr"
external const_bitcast : llvalue -> lltype -> llvalue = "llvm_const_bitcast"
@@ -674,7 +668,6 @@ external const_trunc_or_bitcast : llvalue -> lltype -> llvalue
= "llvm_const_trunc_or_bitcast"
external const_pointercast : llvalue -> lltype -> llvalue
= "llvm_const_pointercast"
-external const_fpcast : llvalue -> lltype -> llvalue = "llvm_const_fpcast"
external const_extractelement : llvalue -> llvalue -> llvalue
= "llvm_const_extractelement"
external const_insertelement : llvalue -> llvalue -> llvalue -> llvalue
diff --git a/llvm/bindings/ocaml/llvm/llvm.mli b/llvm/bindings/ocaml/llvm/llvm.mli
index ee691ca83624455..f9aab89e4bddfbd 100644
--- a/llvm/bindings/ocaml/llvm/llvm.mli
+++ b/llvm/bindings/ocaml/llvm/llvm.mli
@@ -1171,36 +1171,6 @@ val const_in_bounds_gep : lltype -> llvalue -> llvalue array -> llvalue
See the method [llvm::ConstantExpr::getTrunc]. *)
val const_trunc : llvalue -> lltype -> llvalue
-(** [const_fptrunc c ty] returns the constant truncation of floating point
- constant [c] to the smaller floating point type [ty].
- See the method [llvm::ConstantExpr::getFPTrunc]. *)
-val const_fptrunc : llvalue -> lltype -> llvalue
-
-(** [const_fpext c ty] returns the constant extension of floating point constant
- [c] to the larger floating point type [ty].
- See the method [llvm::ConstantExpr::getFPExt]. *)
-val const_fpext : llvalue -> lltype -> llvalue
-
-(** [const_uitofp c ty] returns the constant floating point conversion of
- unsigned integer constant [c] to the floating point type [ty].
- See the method [llvm::ConstantExpr::getUIToFP]. *)
-val const_uitofp : llvalue -> lltype -> llvalue
-
-(** [const_sitofp c ty] returns the constant floating point conversion of
- signed integer constant [c] to the floating point type [ty].
- See the method [llvm::ConstantExpr::getSIToFP]. *)
-val const_sitofp : llvalue -> lltype -> llvalue
-
-(** [const_fptoui c ty] returns the constant unsigned integer conversion of
- floating point constant [c] to integer type [ty].
- See the method [llvm::ConstantExpr::getFPToUI]. *)
-val const_fptoui : llvalue -> lltype -> llvalue
-
-(** [const_fptoui c ty] returns the constant unsigned integer conversion of
- floating point constant [c] to integer type [ty].
- See the method [llvm::ConstantExpr::getFPToSI]. *)
-val const_fptosi : llvalue -> lltype -> llvalue
-
(** [const_ptrtoint c ty] returns the constant integer conversion of
pointer constant [c] to integer type [ty].
See the method [llvm::ConstantExpr::getPtrToInt]. *)
@@ -1226,11 +1196,6 @@ val const_trunc_or_bitcast : llvalue -> lltype -> llvalue
See the method [llvm::ConstantExpr::getPointerCast]. *)
val const_pointercast : llvalue -> lltype -> llvalue
-(** [const_fpcast c ty] returns a constant fpext, bitcast, or fptrunc for fp ->
- fp casts of constant [c] to type [ty].
- See the method [llvm::ConstantExpr::getFPCast]. *)
-val const_fpcast : llvalue -> lltype -> llvalue
-
(** [const_extractelement vec i] returns the constant [i]th element of
constant vector [vec]. [i] must be a constant [i32] value unsigned less than
the size of the vector.
diff --git a/llvm/bindings/ocaml/llvm/llvm_ocaml.c b/llvm/bindings/ocaml/llvm/llvm_ocaml.c
index 7c5df6643d21a8a..4c4c49027206c05 100644
--- a/llvm/bindings/ocaml/llvm/llvm_ocaml.c
+++ b/llvm/bindings/ocaml/llvm/llvm_ocaml.c
@@ -1271,42 +1271,6 @@ value llvm_const_trunc(value CV, value T) {
return to_val(Value);
}
-/* llvalue -> lltype -> llvalue */
-value llvm_const_fptrunc(value CV, value T) {
- LLVMValueRef Value = LLVMConstFPTrunc(Value_val(CV), Type_val(T));
- return to_val(Value);
-}
-
-/* llvalue -> lltype -> llvalue */
-value llvm_const_fpext(value CV, value T) {
- LLVMValueRef Value = LLVMConstFPExt(Value_val(CV), Type_val(T));
- return to_val(Value);
-}
-
-/* llvalue -> lltype -> llvalue */
-value llvm_const_uitofp(value CV, value T) {
- LLVMValueRef Value = LLVMConstUIToFP(Value_val(CV), Type_val(T));
- return to_val(Value);
-}
-
-/* llvalue -> lltype -> llvalue */
-value llvm_const_sitofp(value CV, value T) {
- LLVMValueRef Value = LLVMConstSIToFP(Value_val(CV), Type_val(T));
- return to_val(Value);
-}
-
-/* llvalue -> lltype -> llvalue */
-value llvm_const_fptoui(value CV, value T) {
- LLVMValueRef Value = LLVMConstFPToUI(Value_val(CV), Type_val(T));
- return to_val(Value);
-}
-
-/* llvalue -> lltype -> llvalue */
-value llvm_const_fptosi(value CV, value T) {
- LLVMValueRef Value = LLVMConstFPToSI(Value_val(CV), Type_val(T));
- return to_val(Value);
-}
-
/* llvalue -> lltype -> llvalue */
value llvm_const_ptrtoint(value CV, value T) {
LLVMValueRef Value = LLVMConstPtrToInt(Value_val(CV), Type_val(T));
@@ -1337,12 +1301,6 @@ value llvm_const_pointercast(value CV, value T) {
return to_val(Value);
}
-/* llvalue -> lltype -> llvalue */
-value llvm_const_fpcast(value CV, value T) {
- LLVMValueRef Value = LLVMConstFPCast(Value_val(CV), Type_val(T));
- return to_val(Value);
-}
-
/* llvalue -> llvalue -> llvalue */
value llvm_const_extractelement(value V, value I) {
LLVMValueRef Value = LLVMConstExtractElement(Value_val(V), Value_val(I));
diff --git a/llvm/docs/LangRef.rst b/llvm/docs/LangRef.rst
index 106dfab7409fa11..5d74e13c789ddd6 100644
--- a/llvm/docs/LangRef.rst
+++ b/llvm/docs/LangRef.rst
@@ -4657,38 +4657,6 @@ The following is the syntax for constant expressions:
``trunc (CST to TYPE)``
Perform the :ref:`trunc operation <i_trunc>` on constants.
-``fptrunc (CST to TYPE)``
- Truncate a floating-point constant to another floating-point type.
- The size of CST must be larger than the size of TYPE. Both types
- must be floating-point.
-``fpext (CST to TYPE)``
- Floating-point extend a constant to another type. The size of CST
- must be smaller or equal to the size of TYPE. Both types must be
- floating-point.
-``fptoui (CST to TYPE)``
- Convert a floating-point constant to the corresponding unsigned
- integer constant. TYPE must be a scalar or vector integer type. CST
- must be of scalar or vector floating-point type. Both CST and TYPE
- must be scalars, or vectors of the same number of elements. If the
- value won't fit in the integer type, the result is a
- :ref:`poison value <poisonvalues>`.
-``fptosi (CST to TYPE)``
- Convert a floating-point constant to the corresponding signed
- integer constant. TYPE must be a scalar or vector integer type. CST
- must be of scalar or vector floating-point type. Both CST and TYPE
- must be scalars, or vectors of the same number of elements. If the
- value won't fit in the integer type, the result is a
- :ref:`poison value <poisonvalues>`.
-``uitofp (CST to TYPE)``
- Convert an unsigned integer constant to the corresponding
- floating-point constant. TYPE must be a scalar or vector floating-point
- type. CST must be of scalar or vector integer type. Both CST and TYPE must
- be scalars, or vectors of the same number of elements.
-``sitofp (CST to TYPE)``
- Convert a signed integer constant to the corresponding floating-point
- constant. TYPE must be a scalar or vector floating-point type.
- CST must be of scalar or vector integer type. Both CST and TYPE must
- be scalars, or vectors of the same number of elements.
``ptrtoint (CST to TYPE)``
Perform the :ref:`ptrtoint operation <i_ptrtoint>` on constants.
``inttoptr (CST to TYPE)``
diff --git a/llvm/docs/ReleaseNotes.rst b/llvm/docs/ReleaseNotes.rst
index 23b54e6a37a7451..2544aebaf2a22ef 100644
--- a/llvm/docs/ReleaseNotes.rst
+++ b/llvm/docs/ReleaseNotes.rst
@@ -59,6 +59,12 @@ Changes to the LLVM IR
* ``or``
* ``zext``
* ``sext``
+ * ``fptrunc``
+ * ``fpext``
+ * ``fptoui``
+ * ``fptosi``
+ * ``uitofp``
+ * ``sitofp``
* Added `llvm.exp10` intrinsic.
@@ -173,6 +179,13 @@ Changes to the C API
* ``LLVMConstZExtOrBitCast``
* ``LLVMConstSExtOrBitCast``
* ``LLVMConstIntCast``
+ * ``LLVMConstFPTrunc``
+ * ``LLVMConstFPExt``
+ * ``LLVMConstFPToUI``
+ * ``LLVMConstFPToSI``
+ * ``LLVMConstUIToFP``
+ * ``LLVMConstSIToFP``
+ * ``LLVMConstFPCast``
* Added ``LLVMCreateTargetMachineWithOptions``, along with helper functions for
an opaque option structure, as an alternative to ``LLVMCreateTargetMachine``.
diff --git a/llvm/include/llvm-c/Core.h b/llvm/include/llvm-c/Core.h
index 4fc88b2b64eacea..ceeb74bd4e6fa99 100644
--- a/llvm/include/llvm-c/Core.h
+++ b/llvm/include/llvm-c/Core.h
@@ -2290,12 +2290,6 @@ LLVMValueRef LLVMConstInBoundsGEP2(LLVMTypeRef Ty, LLVMValueRef ConstantVal,
LLVMValueRef *ConstantIndices,
unsigned NumIndices);
LLVMValueRef LLVMConstTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
-LLVMValueRef LLVMConstFPTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
-LLVMValueRef LLVMConstFPExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
-LLVMValueRef LLVMConstUIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
-LLVMValueRef LLVMConstSIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
-LLVMValueRef LLVMConstFPToUI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
-LLVMValueRef LLVMConstFPToSI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
LLVMValueRef LLVMConstPtrToInt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
LLVMValueRef LLVMConstIntToPtr(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
LLVMValueRef LLVMConstBitCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
@@ -2304,7 +2298,6 @@ LLVMValueRef LLVMConstTruncOrBitCast(LLVMValueRef ConstantVal,
LLVMTypeRef ToType);
LLVMValueRef LLVMConstPointerCast(LLVMValueRef ConstantVal,
LLVMTypeRef ToType);
-LLVMValueRef LLVMConstFPCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
LLVMValueRef LLVMConstExtractElement(LLVMValueRef VectorConstant,
LLVMValueRef IndexConstant);
LLVMValueRef LLVMConstInsertElement(LLVMValueRef VectorConstant,
diff --git a/llvm/include/llvm/IR/Constants.h b/llvm/include/llvm/IR/Constants.h
index 43744ba8a617812..cf3812a79f028fb 100644
--- a/llvm/include/llvm/IR/Constants.h
+++ b/llvm/include/llvm/IR/Constants.h
@@ -1041,14 +1041,6 @@ class ConstantExpr : public Constant {
static Constant *getLShr(Constant *C1, Constant *C2, bool isExact = false);
static Constant *getAShr(Constant *C1, Constant *C2, bool isExact = false);
static Constant *getTrunc(Constant *C, Type *Ty, bool OnlyIfReduced = false);
- static Constant *getFPTrunc(Constant *C, Type *Ty,
- bool OnlyIfReduced = false);
- static Constant *getFPExtend(Constant *C, Type *Ty,
- bool OnlyIfReduced = false);
- static Constant *getUIToFP(Constant *C, Type *Ty, bool OnlyIfReduced = false);
- static Constant *getSIToFP(Constant *C, Type *Ty, bool OnlyIfReduced = false);
- static Constant *getFPToUI(Constant *C, Type *Ty, bool OnlyIfReduced = false);
- static Constant *getFPToSI(Constant *C, Type *Ty, bool OnlyIfReduced = false);
static Constant *getPtrToInt(Constant *C, Type *Ty,
bool OnlyIfReduced = false);
static Constant *getIntToPtr(Constant *C, Type *Ty,
@@ -1158,11 +1150,6 @@ class ConstantExpr : public Constant {
Type *Ty ///< The type to bitcast or addrspacecast C to
);
- /// Create a FPExt, Bitcast or FPTrunc for fp -> fp casts
- static Constant *getFPCast(Constant *C, ///< The integer constant to be casted
- Type *Ty ///< The integer type to cast to
- );
-
/// Return true if this is a convert constant expression
bool isCast() const;
diff --git a/llvm/include/llvm/IR/PatternMatch.h b/llvm/include/llvm/IR/PatternMatch.h
index 2551e81b62b6d0d..f709a5ac52a4125 100644
--- a/llvm/include/llvm/IR/PatternMatch.h
+++ b/llvm/include/llvm/IR/PatternMatch.h
@@ -1697,34 +1697,34 @@ m_ZExtOrSExtOrSelf(const OpTy &Op) {
}
template <typename OpTy>
-inline CastOperator_match<OpTy, Instruction::UIToFP> m_UIToFP(const OpTy &Op) {
- return CastOperator_match<OpTy, Instruction::UIToFP>(Op);
+inline CastInst_match<OpTy, Instruction::UIToFP> m_UIToFP(const OpTy &Op) {
+ return CastInst_match<OpTy, Instruction::UIToFP>(Op);
}
template <typename OpTy>
-inline CastOperator_match<OpTy, Instruction::SIToFP> m_SIToFP(const OpTy &Op) {
- return CastOperator_match<OpTy, Instruction::SIToFP>(Op);
+inline CastInst_match<OpTy, Instruction::SIToFP> m_SIToFP(const OpTy &Op) {
+ return CastInst_match<OpTy, Instruction::SIToFP>(Op);
}
template <typename OpTy>
-inline CastOperator_match<OpTy, Instruction::FPToUI> m_FPToUI(const OpTy &Op) {
- return CastOperator_match<OpTy, Instruction::FPToUI>(Op);
+inline CastInst_match<OpTy, Instruction::FPToUI> m_FPToUI(const OpTy &Op) {
+ return CastInst_match<OpTy, Instruction::FPToUI>(Op);
}
template <typename OpTy>
-inline CastOperator_match<OpTy, Instruction::FPToSI> m_FPToSI(const OpTy &Op) {
- return CastOperator_match<OpTy, Instruction::FPToSI>(Op);
+inline CastInst_match<OpTy, Instruction::FPToSI> m_FPToSI(const OpTy &Op) {
+ return CastInst_match<OpTy, Instruction::FPToSI>(Op);
}
template <typename OpTy>
-inline CastOperator_match<OpTy, Instruction::FPTrunc>
+inline CastInst_match<OpTy, Instruction::FPTrunc>
m_FPTrunc(const OpTy &Op) {
- return CastOperator_match<OpTy, Instruction::FPTrunc>(Op);
+ return CastInst_match<OpTy, Instruction::FPTrunc>(Op);
}
template <typename OpTy>
-inline CastOperator_match<OpTy, Instruction::FPExt> m_FPExt(const OpTy &Op) {
- return CastOperator_match<OpTy, Instruction::FPExt>(Op);
+inline CastInst_match<OpTy, Instruction::FPExt> m_FPExt(const OpTy &Op) {
+ return CastInst_match<OpTy, Instruction::FPExt>(Op);
}
//===----------------------------------------------------------------------===//
diff --git a/llvm/lib/AsmParser/LLParser.cpp b/llvm/lib/AsmParser/LLParser.cpp
index d3abd16204a4534..95fe5ede28a8864 100644
--- a/llvm/lib/AsmParser/LLParser.cpp
+++ b/llvm/lib/AsmParser/LLParser.cpp
@@ -3805,14 +3805,8 @@ bool LLParser::parseValID(ValID &ID, PerFunctionState *PFS, Type *ExpectedTy) {
}
case lltok::kw_trunc:
- case lltok::kw_fptrunc:
- case lltok::kw_fpext:
case lltok::kw_bitcast:
case lltok::kw_addrspacecast:
- case lltok::kw_uitofp:
- case lltok::kw_sitofp:
- case lltok::kw_fptoui:
- case lltok::kw_fptosi:
case lltok::kw_inttoptr:
case lltok::kw_ptrtoint: {
unsigned Opc = Lex.getUIntVal();
@@ -3868,6 +3862,18 @@ bool LLParser::parseValID(ValID &ID, PerFunctionState *PFS, Type *ExpectedTy) {
return error(ID.Loc, "zext constexprs are no longer supported");
case lltok::kw_sext:
return error(ID.Loc, "sext constexprs are no longer supported");
+ case lltok::kw_fptrunc:
+ return error(ID.Loc, "fptrunc constexprs are no longer supported");
+ case lltok::kw_fpext:
+ return error(ID.Loc, "fpext constexprs are no longer supported");
+ case lltok::kw_uitofp:
+ return error(ID.Loc, "uitofp constexprs are no longer supported");
+ case lltok::kw_sitofp:
+ return error(ID.Loc, "sitofp constexprs are no longer supported");
+ case lltok::kw_fptoui:
+ return error(ID.Loc, "fptoui constexprs are no longer supported");
+ case lltok::kw_fptosi:
+ return error(ID.Loc, "fptosi constexprs are no longer supported");
case lltok::kw_icmp:
case lltok::kw_fcmp: {
unsigned PredVal, Opc = Lex.getUIntVal();
diff --git a/llvm/lib/IR/Constants.cpp b/llvm/lib/IR/Constants.cpp
index 16072d2efc95bfd..4e480691558f043 100644
--- a/llvm/lib/IR/Constants.cpp
+++ b/llvm/lib/IR/Constants.cpp
@@ -1968,18 +1968,6 @@ Constant *ConstantExpr::getCast(unsigned oc, Constant *C, Type *Ty,
llvm_unreachable("Invalid cast opcode");
case Instruction::Trunc:
return getTrunc(C, Ty, OnlyIfReduced);
- case Instruction::FPTrunc:
- return getFPTrunc(C, Ty, OnlyIfReduced);
- case Instruction::FPExt:
- return getFPExtend(C, Ty, OnlyIfReduced);
- case Instruction::UIToFP:
- return getUIToFP(C, Ty, OnlyIfReduced);
- case Instruction::SIToFP:
- return getSIToFP(C, Ty, OnlyIfReduced);
- case Instruction::FPToUI:
- return getFPToUI(C, Ty, OnlyIfReduced);
- case Instruction::FPToSI:
- return getFPToSI(C, Ty, OnlyIfReduced);
case Instruction::PtrToInt:
return getPtrToInt(C, Ty, OnlyIfReduced);
case Instruction::IntToPtr:
@@ -2023,18 +2011,6 @@ Constant *ConstantExpr::getPointerBitCastOrAddrSpaceCast(Constant *S,
return getBitCast(S, Ty);
}
-Constant *ConstantExpr::getFPCast(Constant *C, Type *Ty) {
- assert(C->getType()->isFPOrFPVectorTy() && Ty->isFPOrFPVectorTy() &&
- "Invalid cast");
- unsigned SrcBits = C->getType()->getScalarSizeInBits();
- unsigned DstBits = Ty->getScalarSizeInBits();
- if (SrcBits == DstBits)
- return C; // Avoid a useless cast
- Instruction::CastOps opcode =
- (SrcBits > DstBits ? Instruction::FPTrunc : Instruction::FPExt);
- return getCast(opcode, C, Ty);
-}
-
Constant *ConstantExpr::getTrunc(Constant *C, Type *Ty, bool OnlyIfReduced) {
#ifndef NDEBUG
bool fromVec = isa<VectorType>(C->getType());
@@ -2049,74 +2025,6 @@ Constant *ConstantExpr::getTrunc(Constant *C, Type *Ty, bool OnlyIfReduced) {
return getFoldedCast(Instruction::Trunc, C, Ty, OnlyIfReduced);
}
-Constant *ConstantExpr::getFPTrunc(Constant *C, Type *Ty, bool OnlyIfReduced) {
-#ifndef NDEBUG
- bool fromVec = isa<VectorType>(C->getType());
- bool toVec = isa<VectorType>(Ty);
-#endif
- assert((fromVec == toVec) && "Cannot convert from scalar to/from vector");
- assert(C->getType()->isFPOrFPVectorTy() && Ty->isFPOrFPVectorTy() &&
- C->getType()->getScalarSizeInBits() > Ty->getScalarSizeInBits()&&
- "This is an illegal floating point truncation!");
- return getFoldedCast(Instruction::FPTrunc, C, Ty, OnlyIfReduced);
-}
-
-Constant *ConstantExpr::getFPExtend(Constant *C, Type *Ty, bool OnlyIfReduced) {
-#ifndef NDEBUG
- bool fromVec = isa<VectorType>(C->getType());
- bool toVec = isa<VectorType>(Ty);
-#endif
- assert((fromVec == toVec) && "Cannot convert from scalar to/from vector");
- assert(C->getType()->isFPOrFPVectorTy() && Ty->isFPOrFPVectorTy() &&
- C->getType()->getScalarSizeInBits() < Ty->getScalarSizeInBits()&&
- "This is an illegal floating point extension!");
- return getFoldedCast(Instruction::FPExt, C, Ty, OnlyIfReduced);
-}
-
-Constant *ConstantExpr::getUIToFP(Constant *C, Type *Ty, bool OnlyIfReduced) {
-#ifndef NDEBUG
- bool fromVec = isa<VectorType>(C->getType());
- bool toVec = isa<VectorType>(Ty);
-#endif
- assert((fromVec == toVec) && "Cannot convert from scalar to/from vector");
- assert(C->getType()->isIntOrIntVectorTy() && Ty->isFPOrFPVectorTy() &&
- "This is an illegal uint to floating point cast!");
- return getFoldedCast(Instruction::UIToFP, C, Ty, OnlyIfReduced);
-}
-
-Constant *ConstantExpr::getSIToFP(Constant *C, Type *Ty, bool OnlyIfReduced) {
-#ifndef NDEBUG
- bool fromVec = isa<VectorType>(C->getType());
- bool toVec = isa<VectorType>(Ty);
-#endif
- assert((fromVec == toVec) && "Cannot convert from scalar to/from vector");
- assert(C->getType()->isIntOrIntVectorTy() && Ty->i...
[truncated]
|
You can test this locally with the following command:git-clang-format --diff 1c6102d19b445c6d17d3792dde0fc308efebc875 53f2b2d55ae0c39fd96c04925d644a48b8b3db27 -- llvm/bindings/ocaml/llvm/llvm_ocaml.c llvm/include/llvm-c/Core.h llvm/include/llvm/IR/Constants.h llvm/include/llvm/IR/PatternMatch.h llvm/lib/AsmParser/LLParser.cpp llvm/lib/IR/Constants.cpp llvm/lib/IR/Core.cpp llvm/unittests/IR/ConstantsTest.cpp View the diff from clang-format here.diff --git a/llvm/include/llvm-c/Core.h b/llvm/include/llvm-c/Core.h
index ceeb74bd4e6f..02fa4c5b06b7 100644
--- a/llvm/include/llvm-c/Core.h
+++ b/llvm/include/llvm-c/Core.h
@@ -2296,8 +2296,7 @@ LLVMValueRef LLVMConstBitCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
LLVMValueRef LLVMConstAddrSpaceCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
LLVMValueRef LLVMConstTruncOrBitCast(LLVMValueRef ConstantVal,
LLVMTypeRef ToType);
-LLVMValueRef LLVMConstPointerCast(LLVMValueRef ConstantVal,
- LLVMTypeRef ToType);
+LLVMValueRef LLVMConstPointerCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
LLVMValueRef LLVMConstExtractElement(LLVMValueRef VectorConstant,
LLVMValueRef IndexConstant);
LLVMValueRef LLVMConstInsertElement(LLVMValueRef VectorConstant,
diff --git a/llvm/include/llvm/IR/PatternMatch.h b/llvm/include/llvm/IR/PatternMatch.h
index f709a5ac52a4..8b7bbbad109e 100644
--- a/llvm/include/llvm/IR/PatternMatch.h
+++ b/llvm/include/llvm/IR/PatternMatch.h
@@ -1717,8 +1717,7 @@ inline CastInst_match<OpTy, Instruction::FPToSI> m_FPToSI(const OpTy &Op) {
}
template <typename OpTy>
-inline CastInst_match<OpTy, Instruction::FPTrunc>
-m_FPTrunc(const OpTy &Op) {
+inline CastInst_match<OpTy, Instruction::FPTrunc> m_FPTrunc(const OpTy &Op) {
return CastInst_match<OpTy, Instruction::FPTrunc>(Op);
}
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Remove support for the fptrunc, fpext, fptoui, fptosi, uitofp and sitofp constant expressions. All places cerating them have been removed beforehand, so this just removes the APIs and uses of these constant expressions in tests.
With this, the only remaining FP operation that still has constant expression support is fcmp.
This is part of https://discourse.llvm.org/t/rfc-remove-most-constant-expressions/63179.