Skip to content

[IR] Remove FP cast constant expressions #71408

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

Merged
merged 1 commit into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions llvm/bindings/ocaml/llvm/llvm.ml
Original file line number Diff line number Diff line change
Expand Up @@ -661,20 +661,13 @@ 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"
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
Expand Down
35 changes: 0 additions & 35 deletions llvm/bindings/ocaml/llvm/llvm.mli
Original file line number Diff line number Diff line change
Expand Up @@ -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]. *)
Expand All @@ -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.
Expand Down
42 changes: 0 additions & 42 deletions llvm/bindings/ocaml/llvm/llvm_ocaml.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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));
Expand Down
32 changes: 0 additions & 32 deletions llvm/docs/LangRef.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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)``
Expand Down
13 changes: 13 additions & 0 deletions llvm/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ Changes to the LLVM IR
* ``or``
* ``zext``
* ``sext``
* ``fptrunc``
* ``fpext``
* ``fptoui``
* ``fptosi``
* ``uitofp``
* ``sitofp``

* Added `llvm.exp10` intrinsic.

Expand Down Expand Up @@ -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``.
Expand Down
7 changes: 0 additions & 7 deletions llvm/include/llvm-c/Core.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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,
Expand Down
13 changes: 0 additions & 13 deletions llvm/include/llvm/IR/Constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;

Expand Down
24 changes: 12 additions & 12 deletions llvm/include/llvm/IR/PatternMatch.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

//===----------------------------------------------------------------------===//
Expand Down
18 changes: 12 additions & 6 deletions llvm/lib/AsmParser/LLParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down
Loading