Skip to content

Commit d8b2e43

Browse files
authored
[IR] Remove mul constant expression (#127046)
Remove support for the mul constant expression, which has previously already been marked as undesirable. This removes the APIs to create mul expressions and updates tests to stop using mul expressions. Part of: https://discourse.llvm.org/t/rfc-remove-most-constant-expressions/63179
1 parent 0949330 commit d8b2e43

31 files changed

+64
-174
lines changed

llvm/bindings/ocaml/llvm/llvm.ml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -655,9 +655,6 @@ external const_nuw_add : llvalue -> llvalue -> llvalue = "llvm_const_nuw_add"
655655
external const_sub : llvalue -> llvalue -> llvalue = "llvm_const_sub"
656656
external const_nsw_sub : llvalue -> llvalue -> llvalue = "llvm_const_nsw_sub"
657657
external const_nuw_sub : llvalue -> llvalue -> llvalue = "llvm_const_nuw_sub"
658-
external const_mul : llvalue -> llvalue -> llvalue = "llvm_const_mul"
659-
external const_nsw_mul : llvalue -> llvalue -> llvalue = "llvm_const_nsw_mul"
660-
external const_nuw_mul : llvalue -> llvalue -> llvalue = "llvm_const_nuw_mul"
661658
external const_xor : llvalue -> llvalue -> llvalue = "llvm_const_xor"
662659
external const_gep : lltype -> llvalue -> llvalue array -> llvalue
663660
= "llvm_const_gep"

llvm/bindings/ocaml/llvm/llvm.mli

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1131,20 +1131,6 @@ val const_nsw_sub : llvalue -> llvalue -> llvalue
11311131
See the method [llvm::ConstantExpr::getNSWSub]. *)
11321132
val const_nuw_sub : llvalue -> llvalue -> llvalue
11331133

1134-
(** [const_mul c1 c2] returns the constant product of two constants.
1135-
See the method [llvm::ConstantExpr::getMul]. *)
1136-
val const_mul : llvalue -> llvalue -> llvalue
1137-
1138-
(** [const_nsw_mul c1 c2] returns the constant product of two constants with
1139-
no signed wrapping. The result is undefined if the sum overflows.
1140-
See the method [llvm::ConstantExpr::getNSWMul]. *)
1141-
val const_nsw_mul : llvalue -> llvalue -> llvalue
1142-
1143-
(** [const_nuw_mul c1 c2] returns the constant product of two constants with
1144-
no unsigned wrapping. The result is undefined if the sum overflows.
1145-
See the method [llvm::ConstantExpr::getNSWMul]. *)
1146-
val const_nuw_mul : llvalue -> llvalue -> llvalue
1147-
11481134
(** [const_xor c1 c2] returns the constant bitwise [XOR] of two integer
11491135
constants.
11501136
See the method [llvm::ConstantExpr::getXor]. *)

llvm/bindings/ocaml/llvm/llvm_ocaml.c

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1210,24 +1210,6 @@ value llvm_const_nuw_sub(value LHS, value RHS) {
12101210
return to_val(Value);
12111211
}
12121212

1213-
/* llvalue -> llvalue -> llvalue */
1214-
value llvm_const_mul(value LHS, value RHS) {
1215-
LLVMValueRef Value = LLVMConstMul(Value_val(LHS), Value_val(RHS));
1216-
return to_val(Value);
1217-
}
1218-
1219-
/* llvalue -> llvalue -> llvalue */
1220-
value llvm_const_nsw_mul(value LHS, value RHS) {
1221-
LLVMValueRef Value = LLVMConstNSWMul(Value_val(LHS), Value_val(RHS));
1222-
return to_val(Value);
1223-
}
1224-
1225-
/* llvalue -> llvalue -> llvalue */
1226-
value llvm_const_nuw_mul(value LHS, value RHS) {
1227-
LLVMValueRef Value = LLVMConstNUWMul(Value_val(LHS), Value_val(RHS));
1228-
return to_val(Value);
1229-
}
1230-
12311213
/* llvalue -> llvalue -> llvalue */
12321214
value llvm_const_xor(value LHS, value RHS) {
12331215
LLVMValueRef Value = LLVMConstXor(Value_val(LHS), Value_val(RHS));

llvm/docs/LangRef.rst

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5113,10 +5113,6 @@ The following is the syntax for constant expressions:
51135113
Perform an addition on constants.
51145114
``sub (LHS, RHS)``
51155115
Perform a subtraction on constants.
5116-
``mul (LHS, RHS)``
5117-
Perform a multiplication on constants.
5118-
``shl (LHS, RHS)``
5119-
Perform a left shift on constants.
51205116
``xor (LHS, RHS)``
51215117
Perform a bitwise xor on constants.
51225118

llvm/docs/ReleaseNotes.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ Changes to the LLVM IR
5757
----------------------
5858

5959
* The `nocapture` attribute has been replaced by `captures(none)`.
60+
* The constant expression variants of the following instructions have been
61+
removed:
62+
63+
* `mul`
6064

6165
Changes to LLVM infrastructure
6266
------------------------------
@@ -121,6 +125,15 @@ Changes to the Python bindings
121125
Changes to the C API
122126
--------------------
123127

128+
* The following functions for creating constant expressions have been removed,
129+
because the underlying constant expressions are no longer supported. Instead,
130+
an instruction should be created using the `LLVMBuildXYZ` APIs, which will
131+
constant fold the operands if possible and create an instruction otherwise:
132+
133+
* `LLVMConstMul`
134+
* `LLVMConstNUWMul`
135+
* `LLVMConstNSWMul`
136+
124137
Changes to the CodeGen infrastructure
125138
-------------------------------------
126139

llvm/include/llvm-c/Core.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2459,9 +2459,6 @@ LLVMValueRef LLVMConstNUWAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant)
24592459
LLVMValueRef LLVMConstSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
24602460
LLVMValueRef LLVMConstNSWSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
24612461
LLVMValueRef LLVMConstNUWSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
2462-
LLVMValueRef LLVMConstMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
2463-
LLVMValueRef LLVMConstNSWMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
2464-
LLVMValueRef LLVMConstNUWMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
24652462
LLVMValueRef LLVMConstXor(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
24662463
LLVMValueRef LLVMConstGEP2(LLVMTypeRef Ty, LLVMValueRef ConstantVal,
24672464
LLVMValueRef *ConstantIndices, unsigned NumIndices);

llvm/include/llvm/IR/Constants.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1143,8 +1143,6 @@ class ConstantExpr : public Constant {
11431143
bool HasNSW = false);
11441144
static Constant *getSub(Constant *C1, Constant *C2, bool HasNUW = false,
11451145
bool HasNSW = false);
1146-
static Constant *getMul(Constant *C1, Constant *C2, bool HasNUW = false,
1147-
bool HasNSW = false);
11481146
static Constant *getXor(Constant *C1, Constant *C2);
11491147
static Constant *getTrunc(Constant *C, Type *Ty, bool OnlyIfReduced = false);
11501148
static Constant *getPtrToInt(Constant *C, Type *Ty,
@@ -1174,14 +1172,6 @@ class ConstantExpr : public Constant {
11741172
return getSub(C1, C2, true, false);
11751173
}
11761174

1177-
static Constant *getNSWMul(Constant *C1, Constant *C2) {
1178-
return getMul(C1, C2, false, true);
1179-
}
1180-
1181-
static Constant *getNUWMul(Constant *C1, Constant *C2) {
1182-
return getMul(C1, C2, true, false);
1183-
}
1184-
11851175
/// If C is a scalar/fixed width vector of known powers of 2, then this
11861176
/// function returns a new scalar/fixed width vector obtained from logBase2
11871177
/// of C. Undef vector elements are set to zero.

llvm/lib/AsmParser/LLParser.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4301,6 +4301,8 @@ bool LLParser::parseValID(ValID &ID, PerFunctionState *PFS, Type *ExpectedTy) {
43014301
return error(ID.Loc, "ashr constexprs are no longer supported");
43024302
case lltok::kw_shl:
43034303
return error(ID.Loc, "shl constexprs are no longer supported");
4304+
case lltok::kw_mul:
4305+
return error(ID.Loc, "mul constexprs are no longer supported");
43044306
case lltok::kw_fneg:
43054307
return error(ID.Loc, "fneg constexprs are no longer supported");
43064308
case lltok::kw_select:
@@ -4329,7 +4331,6 @@ bool LLParser::parseValID(ValID &ID, PerFunctionState *PFS, Type *ExpectedTy) {
43294331
// Binary Operators.
43304332
case lltok::kw_add:
43314333
case lltok::kw_sub:
4332-
case lltok::kw_mul:
43334334
case lltok::kw_xor: {
43344335
bool NUW = false;
43354336
bool NSW = false;

llvm/lib/IR/Constants.cpp

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2422,10 +2422,10 @@ bool ConstantExpr::isSupportedBinOp(unsigned Opcode) {
24222422
case Instruction::LShr:
24232423
case Instruction::AShr:
24242424
case Instruction::Shl:
2425+
case Instruction::Mul:
24252426
return false;
24262427
case Instruction::Add:
24272428
case Instruction::Sub:
2428-
case Instruction::Mul:
24292429
case Instruction::Xor:
24302430
return true;
24312431
default:
@@ -2649,13 +2649,6 @@ Constant *ConstantExpr::getSub(Constant *C1, Constant *C2,
26492649
return get(Instruction::Sub, C1, C2, Flags);
26502650
}
26512651

2652-
Constant *ConstantExpr::getMul(Constant *C1, Constant *C2,
2653-
bool HasNUW, bool HasNSW) {
2654-
unsigned Flags = (HasNUW ? OverflowingBinaryOperator::NoUnsignedWrap : 0) |
2655-
(HasNSW ? OverflowingBinaryOperator::NoSignedWrap : 0);
2656-
return get(Instruction::Mul, C1, C2, Flags);
2657-
}
2658-
26592652
Constant *ConstantExpr::getXor(Constant *C1, Constant *C2) {
26602653
return get(Instruction::Xor, C1, C2);
26612654
}

llvm/lib/IR/Core.cpp

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1803,23 +1803,6 @@ LLVMValueRef LLVMConstNUWSub(LLVMValueRef LHSConstant,
18031803
unwrap<Constant>(RHSConstant)));
18041804
}
18051805

1806-
LLVMValueRef LLVMConstMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
1807-
return wrap(ConstantExpr::getMul(unwrap<Constant>(LHSConstant),
1808-
unwrap<Constant>(RHSConstant)));
1809-
}
1810-
1811-
LLVMValueRef LLVMConstNSWMul(LLVMValueRef LHSConstant,
1812-
LLVMValueRef RHSConstant) {
1813-
return wrap(ConstantExpr::getNSWMul(unwrap<Constant>(LHSConstant),
1814-
unwrap<Constant>(RHSConstant)));
1815-
}
1816-
1817-
LLVMValueRef LLVMConstNUWMul(LLVMValueRef LHSConstant,
1818-
LLVMValueRef RHSConstant) {
1819-
return wrap(ConstantExpr::getNUWMul(unwrap<Constant>(LHSConstant),
1820-
unwrap<Constant>(RHSConstant)));
1821-
}
1822-
18231806
LLVMValueRef LLVMConstXor(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
18241807
return wrap(ConstantExpr::getXor(unwrap<Constant>(LHSConstant),
18251808
unwrap<Constant>(RHSConstant)));

0 commit comments

Comments
 (0)