Skip to content

Commit bbfb13a

Browse files
committed
[ConstExpr] Remove select constant expression
This removes the select constant expression, as part of https://discourse.llvm.org/t/rfc-remove-most-constant-expressions/63179. Uses of this expressions have already been removed in advance, so this just removes related infrastructure and updates tests. Differential Revision: https://reviews.llvm.org/D145382
1 parent b293c62 commit bbfb13a

File tree

38 files changed

+108
-307
lines changed

38 files changed

+108
-307
lines changed

llvm/bindings/ocaml/llvm/llvm.ml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -685,8 +685,6 @@ external const_pointercast : llvalue -> lltype -> llvalue
685685
external const_intcast : llvalue -> lltype -> is_signed:bool -> llvalue
686686
= "llvm_const_intcast"
687687
external const_fpcast : llvalue -> lltype -> llvalue = "llvm_const_fpcast"
688-
external const_select : llvalue -> llvalue -> llvalue -> llvalue
689-
= "llvm_const_select"
690688
external const_extractelement : llvalue -> llvalue -> llvalue
691689
= "llvm_const_extractelement"
692690
external const_insertelement : llvalue -> llvalue -> llvalue -> llvalue

llvm/bindings/ocaml/llvm/llvm.mli

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1268,11 +1268,6 @@ val const_intcast : llvalue -> lltype -> is_signed:bool -> llvalue
12681268
See the method [llvm::ConstantExpr::getFPCast]. *)
12691269
val const_fpcast : llvalue -> lltype -> llvalue
12701270

1271-
(** [const_select cond t f] returns the constant conditional which returns value
1272-
[t] if the boolean constant [cond] is true and the value [f] otherwise.
1273-
See the method [llvm::ConstantExpr::getSelect]. *)
1274-
val const_select : llvalue -> llvalue -> llvalue -> llvalue
1275-
12761271
(** [const_extractelement vec i] returns the constant [i]th element of
12771272
constant vector [vec]. [i] must be a constant [i32] value unsigned less than
12781273
the size of the vector.

llvm/bindings/ocaml/llvm/llvm_ocaml.c

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1385,13 +1385,6 @@ value llvm_const_fpcast(value CV, value T) {
13851385
return to_val(Value);
13861386
}
13871387

1388-
/* llvalue -> llvalue -> llvalue -> llvalue */
1389-
value llvm_const_select(value Cond, value IfTrue, value IfFalse) {
1390-
LLVMValueRef Value =
1391-
LLVMConstSelect(Value_val(Cond), Value_val(IfTrue), Value_val(IfFalse));
1392-
return to_val(Value);
1393-
}
1394-
13951388
/* llvalue -> llvalue -> llvalue */
13961389
value llvm_const_extractelement(value V, value I) {
13971390
LLVMValueRef Value = LLVMConstExtractElement(Value_val(V), Value_val(I));

llvm/docs/ReleaseNotes.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ Changes to the LLVM IR
5656
* The ``nofpclass`` attribute was introduced. This allows more
5757
optimizations around special floating point value comparisons.
5858

59+
* The constant expression variants of the following instructions have been
60+
removed:
61+
62+
* ``select``
63+
5964
Changes to building LLVM
6065
------------------------
6166

@@ -151,6 +156,12 @@ Changes to the C API
151156
These belonged to the no longer supported legacy pass manager.
152157
* As part of the opaque pointer transition, ``LLVMGetElementType`` no longer
153158
gives the pointee type of a pointer type.
159+
* The following functions for creating constant expressions have been removed,
160+
because the underlying constant expressions are no longer supported. Instead,
161+
an instruction should be created using the ``LLVMBuildXYZ`` APIs, which will
162+
constant fold the operands if possible and create an instruction otherwise:
163+
164+
* ``LLVMConstSelect``
154165

155166
Changes to the FastISel infrastructure
156167
--------------------------------------

llvm/include/llvm-c/Core.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2257,9 +2257,6 @@ LLVMValueRef LLVMConstPointerCast(LLVMValueRef ConstantVal,
22572257
LLVMValueRef LLVMConstIntCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType,
22582258
LLVMBool isSigned);
22592259
LLVMValueRef LLVMConstFPCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
2260-
LLVMValueRef LLVMConstSelect(LLVMValueRef ConstantCondition,
2261-
LLVMValueRef ConstantIfTrue,
2262-
LLVMValueRef ConstantIfFalse);
22632260
LLVMValueRef LLVMConstExtractElement(LLVMValueRef VectorConstant,
22642261
LLVMValueRef IndexConstant);
22652262
LLVMValueRef LLVMConstInsertElement(LLVMValueRef VectorConstant,

llvm/include/llvm/IR/Constants.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1208,12 +1208,6 @@ class ConstantExpr : public Constant {
12081208
/// Return true if this is a compare constant expression
12091209
bool isCompare() const;
12101210

1211-
/// Select constant expr
1212-
///
1213-
/// \param OnlyIfReducedTy see \a getWithOperands() docs.
1214-
static Constant *getSelect(Constant *C, Constant *V1, Constant *V2,
1215-
Type *OnlyIfReducedTy = nullptr);
1216-
12171211
/// get - Return a binary or shift operator constant expression,
12181212
/// folding if possible.
12191213
///

llvm/lib/AsmParser/LLParser.cpp

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3882,6 +3882,8 @@ bool LLParser::parseValID(ValID &ID, PerFunctionState *PFS, Type *ExpectedTy) {
38823882
return error(ID.Loc, "frem constexprs are no longer supported");
38833883
case lltok::kw_fneg:
38843884
return error(ID.Loc, "fneg constexprs are no longer supported");
3885+
case lltok::kw_select:
3886+
return error(ID.Loc, "select constexprs are no longer supported");
38853887
case lltok::kw_icmp:
38863888
case lltok::kw_fcmp: {
38873889
unsigned PredVal, Opc = Lex.getUIntVal();
@@ -4011,8 +4013,7 @@ bool LLParser::parseValID(ValID &ID, PerFunctionState *PFS, Type *ExpectedTy) {
40114013
case lltok::kw_getelementptr:
40124014
case lltok::kw_shufflevector:
40134015
case lltok::kw_insertelement:
4014-
case lltok::kw_extractelement:
4015-
case lltok::kw_select: {
4016+
case lltok::kw_extractelement: {
40164017
unsigned Opc = Lex.getUIntVal();
40174018
SmallVector<Constant*, 16> Elts;
40184019
bool InBounds = false;
@@ -4091,13 +4092,6 @@ bool LLParser::parseValID(ValID &ID, PerFunctionState *PFS, Type *ExpectedTy) {
40914092

40924093
ID.ConstantVal = ConstantExpr::getGetElementPtr(Ty, Elts[0], Indices,
40934094
InBounds, InRangeOp);
4094-
} else if (Opc == Instruction::Select) {
4095-
if (Elts.size() != 3)
4096-
return error(ID.Loc, "expected three operands to select");
4097-
if (const char *Reason = SelectInst::areInvalidOperands(Elts[0], Elts[1],
4098-
Elts[2]))
4099-
return error(ID.Loc, Reason);
4100-
ID.ConstantVal = ConstantExpr::getSelect(Elts[0], Elts[1], Elts[2]);
41014095
} else if (Opc == Instruction::ShuffleVector) {
41024096
if (Elts.size() != 3)
41034097
return error(ID.Loc, "expected three operands to shufflevector");

llvm/lib/Bitcode/Reader/BitcodeReader.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1417,7 +1417,13 @@ static bool isConstExprSupported(const BitcodeConstant *BC) {
14171417
if (Opcode == Instruction::GetElementPtr)
14181418
return ConstantExpr::isSupportedGetElementPtr(BC->SrcElemTy);
14191419

1420-
return Opcode != Instruction::FNeg;
1420+
switch (Opcode) {
1421+
case Instruction::FNeg:
1422+
case Instruction::Select:
1423+
return false;
1424+
default:
1425+
return true;
1426+
}
14211427
}
14221428

14231429
Expected<Value *> BitcodeReader::materializeValue(unsigned StartValID,
@@ -1549,9 +1555,6 @@ Expected<Value *> BitcodeReader::materializeValue(unsigned StartValID,
15491555
ArrayRef(ConstOps).drop_front(),
15501556
BC->Flags, BC->getInRangeIndex());
15511557
break;
1552-
case Instruction::Select:
1553-
C = ConstantExpr::getSelect(ConstOps[0], ConstOps[1], ConstOps[2]);
1554-
break;
15551558
case Instruction::ExtractElement:
15561559
C = ConstantExpr::getExtractElement(ConstOps[0], ConstOps[1]);
15571560
break;

llvm/lib/Bitcode/Writer/BitcodeWriter.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2676,12 +2676,6 @@ void ModuleBitcodeWriter::writeConstants(unsigned FirstVal, unsigned LastVal,
26762676
}
26772677
break;
26782678
}
2679-
case Instruction::Select:
2680-
Code = bitc::CST_CODE_CE_SELECT;
2681-
Record.push_back(VE.getValueID(C->getOperand(0)));
2682-
Record.push_back(VE.getValueID(C->getOperand(1)));
2683-
Record.push_back(VE.getValueID(C->getOperand(2)));
2684-
break;
26852679
case Instruction::ExtractElement:
26862680
Code = bitc::CST_CODE_CE_EXTRACTELT;
26872681
Record.push_back(VE.getTypeID(C->getOperand(0)->getType()));

llvm/lib/IR/ConstantFold.cpp

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -593,17 +593,6 @@ Constant *llvm::ConstantFoldSelectInstruction(Constant *Cond,
593593
if (isa<UndefValue>(V1) && NotPoison(V2)) return V2;
594594
if (isa<UndefValue>(V2) && NotPoison(V1)) return V1;
595595

596-
if (ConstantExpr *TrueVal = dyn_cast<ConstantExpr>(V1)) {
597-
if (TrueVal->getOpcode() == Instruction::Select)
598-
if (TrueVal->getOperand(0) == Cond)
599-
return ConstantExpr::getSelect(Cond, TrueVal->getOperand(1), V2);
600-
}
601-
if (ConstantExpr *FalseVal = dyn_cast<ConstantExpr>(V2)) {
602-
if (FalseVal->getOpcode() == Instruction::Select)
603-
if (FalseVal->getOperand(0) == Cond)
604-
return ConstantExpr::getSelect(Cond, V1, FalseVal->getOperand(2));
605-
}
606-
607596
return nullptr;
608597
}
609598

0 commit comments

Comments
 (0)