Skip to content

Commit deab451

Browse files
authored
[IR] Remove support for icmp and fcmp constant expressions (#93038)
Remove support for the icmp and fcmp constant expressions. This is part of: https://discourse.llvm.org/t/rfc-remove-most-constant-expressions/63179 As usual, many of the updated tests will no longer test what they were originally intended to -- this is hard to preserve when constant expressions get removed, and in many cases just impossible as the existence of a specific kind of constant expression was the cause of the issue in the first place.
1 parent 46672c1 commit deab451

File tree

118 files changed

+360
-741
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

118 files changed

+360
-741
lines changed

lld/test/COFF/lto-weak-undefined.ll

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ target triple = "x86_64-pc-windows-msvc"
1919

2020
define dso_local i32 @main() {
2121
entry:
22-
br i1 icmp ne (ptr @optionalFunc, ptr null), label %if.then, label %if.end
22+
%cmp = icmp ne ptr @optionalFunc, null
23+
br i1 %cmp, label %if.then, label %if.end
2324

2425
if.then:
2526
tail call void @optionalFunc()

llvm/bindings/ocaml/llvm/llvm.ml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -651,10 +651,6 @@ external const_mul : llvalue -> llvalue -> llvalue = "llvm_const_mul"
651651
external const_nsw_mul : llvalue -> llvalue -> llvalue = "llvm_const_nsw_mul"
652652
external const_nuw_mul : llvalue -> llvalue -> llvalue = "llvm_const_nuw_mul"
653653
external const_xor : llvalue -> llvalue -> llvalue = "llvm_const_xor"
654-
external const_icmp : Icmp.t -> llvalue -> llvalue -> llvalue
655-
= "llvm_const_icmp"
656-
external const_fcmp : Fcmp.t -> llvalue -> llvalue -> llvalue
657-
= "llvm_const_fcmp"
658654
external const_shl : llvalue -> llvalue -> llvalue = "llvm_const_shl"
659655
external const_gep : lltype -> llvalue -> llvalue array -> llvalue
660656
= "llvm_const_gep"

llvm/bindings/ocaml/llvm/llvm.mli

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1136,16 +1136,6 @@ val const_nuw_mul : llvalue -> llvalue -> llvalue
11361136
See the method [llvm::ConstantExpr::getXor]. *)
11371137
val const_xor : llvalue -> llvalue -> llvalue
11381138

1139-
(** [const_icmp pred c1 c2] returns the constant comparison of two integer
1140-
constants, [c1 pred c2].
1141-
See the method [llvm::ConstantExpr::getICmp]. *)
1142-
val const_icmp : Icmp.t -> llvalue -> llvalue -> llvalue
1143-
1144-
(** [const_fcmp pred c1 c2] returns the constant comparison of two floating
1145-
point constants, [c1 pred c2].
1146-
See the method [llvm::ConstantExpr::getFCmp]. *)
1147-
val const_fcmp : Fcmp.t -> llvalue -> llvalue -> llvalue
1148-
11491139
(** [const_shl c1 c2] returns the constant integer [c1] left-shifted by the
11501140
constant integer [c2].
11511141
See the method [llvm::ConstantExpr::getShl]. *)

llvm/bindings/ocaml/llvm/llvm_ocaml.c

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1224,18 +1224,6 @@ value llvm_const_xor(value LHS, value RHS) {
12241224
return to_val(Value);
12251225
}
12261226

1227-
/* Icmp.t -> llvalue -> llvalue -> llvalue */
1228-
value llvm_const_icmp(value Pred, value LHSConstant, value RHSConstant) {
1229-
return to_val(LLVMConstICmp(Int_val(Pred) + LLVMIntEQ, Value_val(LHSConstant),
1230-
Value_val(RHSConstant)));
1231-
}
1232-
1233-
/* Fcmp.t -> llvalue -> llvalue -> llvalue */
1234-
value llvm_const_fcmp(value Pred, value LHSConstant, value RHSConstant) {
1235-
return to_val(LLVMConstFCmp(Int_val(Pred), Value_val(LHSConstant),
1236-
Value_val(RHSConstant)));
1237-
}
1238-
12391227
/* llvalue -> llvalue -> llvalue */
12401228
value llvm_const_shl(value LHS, value RHS) {
12411229
LLVMValueRef Value = LLVMConstShl(Value_val(LHS), Value_val(RHS));

llvm/docs/LangRef.rst

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4821,10 +4821,6 @@ The following is the syntax for constant expressions:
48214821
required to make sense for the type of "pointer to TY". These indexes
48224822
may be implicitly sign-extended or truncated to match the index size
48234823
of CSTPTR's address space.
4824-
``icmp COND (VAL1, VAL2)``
4825-
Perform the :ref:`icmp operation <i_icmp>` on constants.
4826-
``fcmp COND (VAL1, VAL2)``
4827-
Perform the :ref:`fcmp operation <i_fcmp>` on constants.
48284824
``extractelement (VAL, IDX)``
48294825
Perform the :ref:`extractelement operation <i_extractelement>` on
48304826
constants.

llvm/docs/ReleaseNotes.rst

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ Changes to the LLVM IR
5656
* Renamed ``llvm.experimental.vector.splice`` intrinsic to ``llvm.vector.splice``.
5757
* Renamed ``llvm.experimental.vector.interleave2`` intrinsic to ``llvm.vector.interleave2``.
5858
* Renamed ``llvm.experimental.vector.deinterleave2`` intrinsic to ``llvm.vector.deinterleave2``.
59+
* The constant expression variants of the following instructions have been
60+
removed:
61+
62+
* ``icmp``
63+
* ``fcmp``
5964

6065
Changes to LLVM infrastructure
6166
------------------------------
@@ -191,6 +196,14 @@ Changes to the C API
191196
* ``LLVMGetCallBrNumIndirectDests``
192197
* ``LLVMGetCallBrIndirectDest``
193198

199+
* The following functions for creating constant expressions have been removed,
200+
because the underlying constant expressions are no longer supported. Instead,
201+
an instruction should be created using the ``LLVMBuildXYZ`` APIs, which will
202+
constant fold the operands if possible and create an instruction otherwise:
203+
204+
* ``LLVMConstICmp``
205+
* ``LLVMConstFCmp``
206+
194207
Changes to the CodeGen infrastructure
195208
-------------------------------------
196209

llvm/include/llvm-c/Core.h

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2354,10 +2354,6 @@ LLVMValueRef LLVMConstMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
23542354
LLVMValueRef LLVMConstNSWMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
23552355
LLVMValueRef LLVMConstNUWMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
23562356
LLVMValueRef LLVMConstXor(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
2357-
LLVMValueRef LLVMConstICmp(LLVMIntPredicate Predicate,
2358-
LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
2359-
LLVMValueRef LLVMConstFCmp(LLVMRealPredicate Predicate,
2360-
LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
23612357
LLVMValueRef LLVMConstShl(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
23622358
LLVMValueRef LLVMConstGEP2(LLVMTypeRef Ty, LLVMValueRef ConstantVal,
23632359
LLVMValueRef *ConstantIndices, unsigned NumIndices);
@@ -3529,8 +3525,7 @@ LLVMOpcode LLVMGetInstructionOpcode(LLVMValueRef Inst);
35293525
/**
35303526
* Obtain the predicate of an instruction.
35313527
*
3532-
* This is only valid for instructions that correspond to llvm::ICmpInst
3533-
* or llvm::ConstantExpr whose opcode is llvm::Instruction::ICmp.
3528+
* This is only valid for instructions that correspond to llvm::ICmpInst.
35343529
*
35353530
* @see llvm::ICmpInst::getPredicate()
35363531
*/
@@ -3539,8 +3534,7 @@ LLVMIntPredicate LLVMGetICmpPredicate(LLVMValueRef Inst);
35393534
/**
35403535
* Obtain the float predicate of an instruction.
35413536
*
3542-
* This is only valid for instructions that correspond to llvm::FCmpInst
3543-
* or llvm::ConstantExpr whose opcode is llvm::Instruction::FCmp.
3537+
* This is only valid for instructions that correspond to llvm::FCmpInst.
35443538
*
35453539
* @see llvm::FCmpInst::getPredicate()
35463540
*/

llvm/include/llvm/IR/Constants.h

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1234,30 +1234,13 @@ class ConstantExpr : public Constant {
12341234
/// Return true if this is a convert constant expression
12351235
bool isCast() const;
12361236

1237-
/// Return true if this is a compare constant expression
1238-
bool isCompare() const;
1239-
12401237
/// get - Return a binary or shift operator constant expression,
12411238
/// folding if possible.
12421239
///
12431240
/// \param OnlyIfReducedTy see \a getWithOperands() docs.
12441241
static Constant *get(unsigned Opcode, Constant *C1, Constant *C2,
12451242
unsigned Flags = 0, Type *OnlyIfReducedTy = nullptr);
12461243

1247-
/// Return an ICmp or FCmp comparison operator constant expression.
1248-
///
1249-
/// \param OnlyIfReduced see \a getWithOperands() docs.
1250-
static Constant *getCompare(unsigned short pred, Constant *C1, Constant *C2,
1251-
bool OnlyIfReduced = false);
1252-
1253-
/// get* - Return some common constants without having to
1254-
/// specify the full Instruction::OPCODE identifier.
1255-
///
1256-
static Constant *getICmp(unsigned short pred, Constant *LHS, Constant *RHS,
1257-
bool OnlyIfReduced = false);
1258-
static Constant *getFCmp(unsigned short pred, Constant *LHS, Constant *RHS,
1259-
bool OnlyIfReduced = false);
1260-
12611244
/// Getelementptr form. Value* is only accepted for convenience;
12621245
/// all elements must be Constants.
12631246
///
@@ -1318,10 +1301,6 @@ class ConstantExpr : public Constant {
13181301
/// Return the opcode at the root of this constant expression
13191302
unsigned getOpcode() const { return getSubclassDataFromValue(); }
13201303

1321-
/// Return the ICMP or FCMP predicate value. Assert if this is not an ICMP or
1322-
/// FCMP constant expression.
1323-
unsigned getPredicate() const;
1324-
13251304
/// Assert that this is a shufflevector and return the mask. See class
13261305
/// ShuffleVectorInst for a description of the mask representation.
13271306
ArrayRef<int> getShuffleMask() const;

llvm/lib/Analysis/ConstantFolding.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1009,12 +1009,8 @@ Constant *ConstantFoldInstOperandsImpl(const Value *InstOrCE, unsigned Opcode,
10091009
GEP->getInRange());
10101010
}
10111011

1012-
if (auto *CE = dyn_cast<ConstantExpr>(InstOrCE)) {
1013-
if (CE->isCompare())
1014-
return ConstantFoldCompareInstOperands(CE->getPredicate(), Ops[0], Ops[1],
1015-
DL, TLI);
1012+
if (auto *CE = dyn_cast<ConstantExpr>(InstOrCE))
10161013
return CE->getWithOperands(Ops);
1017-
}
10181014

10191015
switch (Opcode) {
10201016
default: return nullptr;

llvm/lib/AsmParser/LLParser.cpp

Lines changed: 3 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4176,37 +4176,9 @@ bool LLParser::parseValID(ValID &ID, PerFunctionState *PFS, Type *ExpectedTy) {
41764176
case lltok::kw_fptosi:
41774177
return error(ID.Loc, "fptosi constexprs are no longer supported");
41784178
case lltok::kw_icmp:
4179-
case lltok::kw_fcmp: {
4180-
unsigned PredVal, Opc = Lex.getUIntVal();
4181-
Constant *Val0, *Val1;
4182-
Lex.Lex();
4183-
if (parseCmpPredicate(PredVal, Opc) ||
4184-
parseToken(lltok::lparen, "expected '(' in compare constantexpr") ||
4185-
parseGlobalTypeAndValue(Val0) ||
4186-
parseToken(lltok::comma, "expected comma in compare constantexpr") ||
4187-
parseGlobalTypeAndValue(Val1) ||
4188-
parseToken(lltok::rparen, "expected ')' in compare constantexpr"))
4189-
return true;
4190-
4191-
if (Val0->getType() != Val1->getType())
4192-
return error(ID.Loc, "compare operands must have the same type");
4193-
4194-
CmpInst::Predicate Pred = (CmpInst::Predicate)PredVal;
4195-
4196-
if (Opc == Instruction::FCmp) {
4197-
if (!Val0->getType()->isFPOrFPVectorTy())
4198-
return error(ID.Loc, "fcmp requires floating point operands");
4199-
ID.ConstantVal = ConstantExpr::getFCmp(Pred, Val0, Val1);
4200-
} else {
4201-
assert(Opc == Instruction::ICmp && "Unexpected opcode for CmpInst!");
4202-
if (!Val0->getType()->isIntOrIntVectorTy() &&
4203-
!Val0->getType()->isPtrOrPtrVectorTy())
4204-
return error(ID.Loc, "icmp requires pointer or integer operands");
4205-
ID.ConstantVal = ConstantExpr::getICmp(Pred, Val0, Val1);
4206-
}
4207-
ID.Kind = ValID::t_Constant;
4208-
return false;
4209-
}
4179+
return error(ID.Loc, "icmp constexprs are no longer supported");
4180+
case lltok::kw_fcmp:
4181+
return error(ID.Loc, "fcmp constexprs are no longer supported");
42104182

42114183
// Binary Operators.
42124184
case lltok::kw_add:

0 commit comments

Comments
 (0)