Skip to content

Commit 17764d2

Browse files
authored
[IR] Remove FP cast constant expressions (#71408)
Remove support for the fptrunc, fpext, fptoui, fptosi, uitofp and sitofp constant expressions. All places creating 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.
1 parent a5c1eca commit 17764d2

File tree

20 files changed

+120
-373
lines changed

20 files changed

+120
-373
lines changed

llvm/bindings/ocaml/llvm/llvm.ml

-7
Original file line numberDiff line numberDiff line change
@@ -661,20 +661,13 @@ external const_gep : lltype -> llvalue -> llvalue array -> llvalue
661661
external const_in_bounds_gep : lltype -> llvalue -> llvalue array -> llvalue
662662
= "llvm_const_in_bounds_gep"
663663
external const_trunc : llvalue -> lltype -> llvalue = "llvm_const_trunc"
664-
external const_fptrunc : llvalue -> lltype -> llvalue = "llvm_const_fptrunc"
665-
external const_fpext : llvalue -> lltype -> llvalue = "llvm_const_fpext"
666-
external const_uitofp : llvalue -> lltype -> llvalue = "llvm_const_uitofp"
667-
external const_sitofp : llvalue -> lltype -> llvalue = "llvm_const_sitofp"
668-
external const_fptoui : llvalue -> lltype -> llvalue = "llvm_const_fptoui"
669-
external const_fptosi : llvalue -> lltype -> llvalue = "llvm_const_fptosi"
670664
external const_ptrtoint : llvalue -> lltype -> llvalue = "llvm_const_ptrtoint"
671665
external const_inttoptr : llvalue -> lltype -> llvalue = "llvm_const_inttoptr"
672666
external const_bitcast : llvalue -> lltype -> llvalue = "llvm_const_bitcast"
673667
external const_trunc_or_bitcast : llvalue -> lltype -> llvalue
674668
= "llvm_const_trunc_or_bitcast"
675669
external const_pointercast : llvalue -> lltype -> llvalue
676670
= "llvm_const_pointercast"
677-
external const_fpcast : llvalue -> lltype -> llvalue = "llvm_const_fpcast"
678671
external const_extractelement : llvalue -> llvalue -> llvalue
679672
= "llvm_const_extractelement"
680673
external const_insertelement : llvalue -> llvalue -> llvalue -> llvalue

llvm/bindings/ocaml/llvm/llvm.mli

-35
Original file line numberDiff line numberDiff line change
@@ -1171,36 +1171,6 @@ val const_in_bounds_gep : lltype -> llvalue -> llvalue array -> llvalue
11711171
See the method [llvm::ConstantExpr::getTrunc]. *)
11721172
val const_trunc : llvalue -> lltype -> llvalue
11731173

1174-
(** [const_fptrunc c ty] returns the constant truncation of floating point
1175-
constant [c] to the smaller floating point type [ty].
1176-
See the method [llvm::ConstantExpr::getFPTrunc]. *)
1177-
val const_fptrunc : llvalue -> lltype -> llvalue
1178-
1179-
(** [const_fpext c ty] returns the constant extension of floating point constant
1180-
[c] to the larger floating point type [ty].
1181-
See the method [llvm::ConstantExpr::getFPExt]. *)
1182-
val const_fpext : llvalue -> lltype -> llvalue
1183-
1184-
(** [const_uitofp c ty] returns the constant floating point conversion of
1185-
unsigned integer constant [c] to the floating point type [ty].
1186-
See the method [llvm::ConstantExpr::getUIToFP]. *)
1187-
val const_uitofp : llvalue -> lltype -> llvalue
1188-
1189-
(** [const_sitofp c ty] returns the constant floating point conversion of
1190-
signed integer constant [c] to the floating point type [ty].
1191-
See the method [llvm::ConstantExpr::getSIToFP]. *)
1192-
val const_sitofp : llvalue -> lltype -> llvalue
1193-
1194-
(** [const_fptoui c ty] returns the constant unsigned integer conversion of
1195-
floating point constant [c] to integer type [ty].
1196-
See the method [llvm::ConstantExpr::getFPToUI]. *)
1197-
val const_fptoui : llvalue -> lltype -> llvalue
1198-
1199-
(** [const_fptoui c ty] returns the constant unsigned integer conversion of
1200-
floating point constant [c] to integer type [ty].
1201-
See the method [llvm::ConstantExpr::getFPToSI]. *)
1202-
val const_fptosi : llvalue -> lltype -> llvalue
1203-
12041174
(** [const_ptrtoint c ty] returns the constant integer conversion of
12051175
pointer constant [c] to integer type [ty].
12061176
See the method [llvm::ConstantExpr::getPtrToInt]. *)
@@ -1226,11 +1196,6 @@ val const_trunc_or_bitcast : llvalue -> lltype -> llvalue
12261196
See the method [llvm::ConstantExpr::getPointerCast]. *)
12271197
val const_pointercast : llvalue -> lltype -> llvalue
12281198

1229-
(** [const_fpcast c ty] returns a constant fpext, bitcast, or fptrunc for fp ->
1230-
fp casts of constant [c] to type [ty].
1231-
See the method [llvm::ConstantExpr::getFPCast]. *)
1232-
val const_fpcast : llvalue -> lltype -> llvalue
1233-
12341199
(** [const_extractelement vec i] returns the constant [i]th element of
12351200
constant vector [vec]. [i] must be a constant [i32] value unsigned less than
12361201
the size of the vector.

llvm/bindings/ocaml/llvm/llvm_ocaml.c

-42
Original file line numberDiff line numberDiff line change
@@ -1271,42 +1271,6 @@ value llvm_const_trunc(value CV, value T) {
12711271
return to_val(Value);
12721272
}
12731273

1274-
/* llvalue -> lltype -> llvalue */
1275-
value llvm_const_fptrunc(value CV, value T) {
1276-
LLVMValueRef Value = LLVMConstFPTrunc(Value_val(CV), Type_val(T));
1277-
return to_val(Value);
1278-
}
1279-
1280-
/* llvalue -> lltype -> llvalue */
1281-
value llvm_const_fpext(value CV, value T) {
1282-
LLVMValueRef Value = LLVMConstFPExt(Value_val(CV), Type_val(T));
1283-
return to_val(Value);
1284-
}
1285-
1286-
/* llvalue -> lltype -> llvalue */
1287-
value llvm_const_uitofp(value CV, value T) {
1288-
LLVMValueRef Value = LLVMConstUIToFP(Value_val(CV), Type_val(T));
1289-
return to_val(Value);
1290-
}
1291-
1292-
/* llvalue -> lltype -> llvalue */
1293-
value llvm_const_sitofp(value CV, value T) {
1294-
LLVMValueRef Value = LLVMConstSIToFP(Value_val(CV), Type_val(T));
1295-
return to_val(Value);
1296-
}
1297-
1298-
/* llvalue -> lltype -> llvalue */
1299-
value llvm_const_fptoui(value CV, value T) {
1300-
LLVMValueRef Value = LLVMConstFPToUI(Value_val(CV), Type_val(T));
1301-
return to_val(Value);
1302-
}
1303-
1304-
/* llvalue -> lltype -> llvalue */
1305-
value llvm_const_fptosi(value CV, value T) {
1306-
LLVMValueRef Value = LLVMConstFPToSI(Value_val(CV), Type_val(T));
1307-
return to_val(Value);
1308-
}
1309-
13101274
/* llvalue -> lltype -> llvalue */
13111275
value llvm_const_ptrtoint(value CV, value T) {
13121276
LLVMValueRef Value = LLVMConstPtrToInt(Value_val(CV), Type_val(T));
@@ -1337,12 +1301,6 @@ value llvm_const_pointercast(value CV, value T) {
13371301
return to_val(Value);
13381302
}
13391303

1340-
/* llvalue -> lltype -> llvalue */
1341-
value llvm_const_fpcast(value CV, value T) {
1342-
LLVMValueRef Value = LLVMConstFPCast(Value_val(CV), Type_val(T));
1343-
return to_val(Value);
1344-
}
1345-
13461304
/* llvalue -> llvalue -> llvalue */
13471305
value llvm_const_extractelement(value V, value I) {
13481306
LLVMValueRef Value = LLVMConstExtractElement(Value_val(V), Value_val(I));

llvm/docs/LangRef.rst

-32
Original file line numberDiff line numberDiff line change
@@ -4657,38 +4657,6 @@ The following is the syntax for constant expressions:
46574657

46584658
``trunc (CST to TYPE)``
46594659
Perform the :ref:`trunc operation <i_trunc>` on constants.
4660-
``fptrunc (CST to TYPE)``
4661-
Truncate a floating-point constant to another floating-point type.
4662-
The size of CST must be larger than the size of TYPE. Both types
4663-
must be floating-point.
4664-
``fpext (CST to TYPE)``
4665-
Floating-point extend a constant to another type. The size of CST
4666-
must be smaller or equal to the size of TYPE. Both types must be
4667-
floating-point.
4668-
``fptoui (CST to TYPE)``
4669-
Convert a floating-point constant to the corresponding unsigned
4670-
integer constant. TYPE must be a scalar or vector integer type. CST
4671-
must be of scalar or vector floating-point type. Both CST and TYPE
4672-
must be scalars, or vectors of the same number of elements. If the
4673-
value won't fit in the integer type, the result is a
4674-
:ref:`poison value <poisonvalues>`.
4675-
``fptosi (CST to TYPE)``
4676-
Convert a floating-point constant to the corresponding signed
4677-
integer constant. TYPE must be a scalar or vector integer type. CST
4678-
must be of scalar or vector floating-point type. Both CST and TYPE
4679-
must be scalars, or vectors of the same number of elements. If the
4680-
value won't fit in the integer type, the result is a
4681-
:ref:`poison value <poisonvalues>`.
4682-
``uitofp (CST to TYPE)``
4683-
Convert an unsigned integer constant to the corresponding
4684-
floating-point constant. TYPE must be a scalar or vector floating-point
4685-
type. CST must be of scalar or vector integer type. Both CST and TYPE must
4686-
be scalars, or vectors of the same number of elements.
4687-
``sitofp (CST to TYPE)``
4688-
Convert a signed integer constant to the corresponding floating-point
4689-
constant. TYPE must be a scalar or vector floating-point type.
4690-
CST must be of scalar or vector integer type. Both CST and TYPE must
4691-
be scalars, or vectors of the same number of elements.
46924660
``ptrtoint (CST to TYPE)``
46934661
Perform the :ref:`ptrtoint operation <i_ptrtoint>` on constants.
46944662
``inttoptr (CST to TYPE)``

llvm/docs/ReleaseNotes.rst

+13
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,12 @@ Changes to the LLVM IR
5959
* ``or``
6060
* ``zext``
6161
* ``sext``
62+
* ``fptrunc``
63+
* ``fpext``
64+
* ``fptoui``
65+
* ``fptosi``
66+
* ``uitofp``
67+
* ``sitofp``
6268

6369
* Added `llvm.exp10` intrinsic.
6470

@@ -173,6 +179,13 @@ Changes to the C API
173179
* ``LLVMConstZExtOrBitCast``
174180
* ``LLVMConstSExtOrBitCast``
175181
* ``LLVMConstIntCast``
182+
* ``LLVMConstFPTrunc``
183+
* ``LLVMConstFPExt``
184+
* ``LLVMConstFPToUI``
185+
* ``LLVMConstFPToSI``
186+
* ``LLVMConstUIToFP``
187+
* ``LLVMConstSIToFP``
188+
* ``LLVMConstFPCast``
176189

177190
* Added ``LLVMCreateTargetMachineWithOptions``, along with helper functions for
178191
an opaque option structure, as an alternative to ``LLVMCreateTargetMachine``.

llvm/include/llvm-c/Core.h

-7
Original file line numberDiff line numberDiff line change
@@ -2290,12 +2290,6 @@ LLVMValueRef LLVMConstInBoundsGEP2(LLVMTypeRef Ty, LLVMValueRef ConstantVal,
22902290
LLVMValueRef *ConstantIndices,
22912291
unsigned NumIndices);
22922292
LLVMValueRef LLVMConstTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
2293-
LLVMValueRef LLVMConstFPTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
2294-
LLVMValueRef LLVMConstFPExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
2295-
LLVMValueRef LLVMConstUIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
2296-
LLVMValueRef LLVMConstSIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
2297-
LLVMValueRef LLVMConstFPToUI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
2298-
LLVMValueRef LLVMConstFPToSI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
22992293
LLVMValueRef LLVMConstPtrToInt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
23002294
LLVMValueRef LLVMConstIntToPtr(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
23012295
LLVMValueRef LLVMConstBitCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
@@ -2304,7 +2298,6 @@ LLVMValueRef LLVMConstTruncOrBitCast(LLVMValueRef ConstantVal,
23042298
LLVMTypeRef ToType);
23052299
LLVMValueRef LLVMConstPointerCast(LLVMValueRef ConstantVal,
23062300
LLVMTypeRef ToType);
2307-
LLVMValueRef LLVMConstFPCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
23082301
LLVMValueRef LLVMConstExtractElement(LLVMValueRef VectorConstant,
23092302
LLVMValueRef IndexConstant);
23102303
LLVMValueRef LLVMConstInsertElement(LLVMValueRef VectorConstant,

llvm/include/llvm/IR/Constants.h

-13
Original file line numberDiff line numberDiff line change
@@ -1041,14 +1041,6 @@ class ConstantExpr : public Constant {
10411041
static Constant *getLShr(Constant *C1, Constant *C2, bool isExact = false);
10421042
static Constant *getAShr(Constant *C1, Constant *C2, bool isExact = false);
10431043
static Constant *getTrunc(Constant *C, Type *Ty, bool OnlyIfReduced = false);
1044-
static Constant *getFPTrunc(Constant *C, Type *Ty,
1045-
bool OnlyIfReduced = false);
1046-
static Constant *getFPExtend(Constant *C, Type *Ty,
1047-
bool OnlyIfReduced = false);
1048-
static Constant *getUIToFP(Constant *C, Type *Ty, bool OnlyIfReduced = false);
1049-
static Constant *getSIToFP(Constant *C, Type *Ty, bool OnlyIfReduced = false);
1050-
static Constant *getFPToUI(Constant *C, Type *Ty, bool OnlyIfReduced = false);
1051-
static Constant *getFPToSI(Constant *C, Type *Ty, bool OnlyIfReduced = false);
10521044
static Constant *getPtrToInt(Constant *C, Type *Ty,
10531045
bool OnlyIfReduced = false);
10541046
static Constant *getIntToPtr(Constant *C, Type *Ty,
@@ -1158,11 +1150,6 @@ class ConstantExpr : public Constant {
11581150
Type *Ty ///< The type to bitcast or addrspacecast C to
11591151
);
11601152

1161-
/// Create a FPExt, Bitcast or FPTrunc for fp -> fp casts
1162-
static Constant *getFPCast(Constant *C, ///< The integer constant to be casted
1163-
Type *Ty ///< The integer type to cast to
1164-
);
1165-
11661153
/// Return true if this is a convert constant expression
11671154
bool isCast() const;
11681155

llvm/include/llvm/IR/PatternMatch.h

+12-12
Original file line numberDiff line numberDiff line change
@@ -1697,34 +1697,34 @@ m_ZExtOrSExtOrSelf(const OpTy &Op) {
16971697
}
16981698

16991699
template <typename OpTy>
1700-
inline CastOperator_match<OpTy, Instruction::UIToFP> m_UIToFP(const OpTy &Op) {
1701-
return CastOperator_match<OpTy, Instruction::UIToFP>(Op);
1700+
inline CastInst_match<OpTy, Instruction::UIToFP> m_UIToFP(const OpTy &Op) {
1701+
return CastInst_match<OpTy, Instruction::UIToFP>(Op);
17021702
}
17031703

17041704
template <typename OpTy>
1705-
inline CastOperator_match<OpTy, Instruction::SIToFP> m_SIToFP(const OpTy &Op) {
1706-
return CastOperator_match<OpTy, Instruction::SIToFP>(Op);
1705+
inline CastInst_match<OpTy, Instruction::SIToFP> m_SIToFP(const OpTy &Op) {
1706+
return CastInst_match<OpTy, Instruction::SIToFP>(Op);
17071707
}
17081708

17091709
template <typename OpTy>
1710-
inline CastOperator_match<OpTy, Instruction::FPToUI> m_FPToUI(const OpTy &Op) {
1711-
return CastOperator_match<OpTy, Instruction::FPToUI>(Op);
1710+
inline CastInst_match<OpTy, Instruction::FPToUI> m_FPToUI(const OpTy &Op) {
1711+
return CastInst_match<OpTy, Instruction::FPToUI>(Op);
17121712
}
17131713

17141714
template <typename OpTy>
1715-
inline CastOperator_match<OpTy, Instruction::FPToSI> m_FPToSI(const OpTy &Op) {
1716-
return CastOperator_match<OpTy, Instruction::FPToSI>(Op);
1715+
inline CastInst_match<OpTy, Instruction::FPToSI> m_FPToSI(const OpTy &Op) {
1716+
return CastInst_match<OpTy, Instruction::FPToSI>(Op);
17171717
}
17181718

17191719
template <typename OpTy>
1720-
inline CastOperator_match<OpTy, Instruction::FPTrunc>
1720+
inline CastInst_match<OpTy, Instruction::FPTrunc>
17211721
m_FPTrunc(const OpTy &Op) {
1722-
return CastOperator_match<OpTy, Instruction::FPTrunc>(Op);
1722+
return CastInst_match<OpTy, Instruction::FPTrunc>(Op);
17231723
}
17241724

17251725
template <typename OpTy>
1726-
inline CastOperator_match<OpTy, Instruction::FPExt> m_FPExt(const OpTy &Op) {
1727-
return CastOperator_match<OpTy, Instruction::FPExt>(Op);
1726+
inline CastInst_match<OpTy, Instruction::FPExt> m_FPExt(const OpTy &Op) {
1727+
return CastInst_match<OpTy, Instruction::FPExt>(Op);
17281728
}
17291729

17301730
//===----------------------------------------------------------------------===//

llvm/lib/AsmParser/LLParser.cpp

+12-6
Original file line numberDiff line numberDiff line change
@@ -3805,14 +3805,8 @@ bool LLParser::parseValID(ValID &ID, PerFunctionState *PFS, Type *ExpectedTy) {
38053805
}
38063806

38073807
case lltok::kw_trunc:
3808-
case lltok::kw_fptrunc:
3809-
case lltok::kw_fpext:
38103808
case lltok::kw_bitcast:
38113809
case lltok::kw_addrspacecast:
3812-
case lltok::kw_uitofp:
3813-
case lltok::kw_sitofp:
3814-
case lltok::kw_fptoui:
3815-
case lltok::kw_fptosi:
38163810
case lltok::kw_inttoptr:
38173811
case lltok::kw_ptrtoint: {
38183812
unsigned Opc = Lex.getUIntVal();
@@ -3868,6 +3862,18 @@ bool LLParser::parseValID(ValID &ID, PerFunctionState *PFS, Type *ExpectedTy) {
38683862
return error(ID.Loc, "zext constexprs are no longer supported");
38693863
case lltok::kw_sext:
38703864
return error(ID.Loc, "sext constexprs are no longer supported");
3865+
case lltok::kw_fptrunc:
3866+
return error(ID.Loc, "fptrunc constexprs are no longer supported");
3867+
case lltok::kw_fpext:
3868+
return error(ID.Loc, "fpext constexprs are no longer supported");
3869+
case lltok::kw_uitofp:
3870+
return error(ID.Loc, "uitofp constexprs are no longer supported");
3871+
case lltok::kw_sitofp:
3872+
return error(ID.Loc, "sitofp constexprs are no longer supported");
3873+
case lltok::kw_fptoui:
3874+
return error(ID.Loc, "fptoui constexprs are no longer supported");
3875+
case lltok::kw_fptosi:
3876+
return error(ID.Loc, "fptosi constexprs are no longer supported");
38713877
case lltok::kw_icmp:
38723878
case lltok::kw_fcmp: {
38733879
unsigned PredVal, Opc = Lex.getUIntVal();

0 commit comments

Comments
 (0)