Skip to content

Commit 56c1d30

Browse files
authored
[IR] Remove support for lshr/ashr constant expressions (#71955)
Remove support for the lshr and ashr constant expressions. All places creating them have been removed beforehand, so this just removes the APIs and uses of these constant expressions in tests. This is part of https://discourse.llvm.org/t/rfc-remove-most-constant-expressions/63179.
1 parent 9cb1673 commit 56c1d30

File tree

23 files changed

+54
-161
lines changed

23 files changed

+54
-161
lines changed

llvm/bindings/ocaml/llvm/llvm.ml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -654,8 +654,6 @@ external const_icmp : Icmp.t -> llvalue -> llvalue -> llvalue
654654
external const_fcmp : Fcmp.t -> llvalue -> llvalue -> llvalue
655655
= "llvm_const_fcmp"
656656
external const_shl : llvalue -> llvalue -> llvalue = "llvm_const_shl"
657-
external const_lshr : llvalue -> llvalue -> llvalue = "llvm_const_lshr"
658-
external const_ashr : llvalue -> llvalue -> llvalue = "llvm_const_ashr"
659657
external const_gep : lltype -> llvalue -> llvalue array -> llvalue
660658
= "llvm_const_gep"
661659
external const_in_bounds_gep : lltype -> llvalue -> llvalue array -> llvalue

llvm/bindings/ocaml/llvm/llvm.mli

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1145,16 +1145,6 @@ val const_fcmp : Fcmp.t -> llvalue -> llvalue -> llvalue
11451145
See the method [llvm::ConstantExpr::getShl]. *)
11461146
val const_shl : llvalue -> llvalue -> llvalue
11471147

1148-
(** [const_lshr c1 c2] returns the constant integer [c1] right-shifted by the
1149-
constant integer [c2] with zero extension.
1150-
See the method [llvm::ConstantExpr::getLShr]. *)
1151-
val const_lshr : llvalue -> llvalue -> llvalue
1152-
1153-
(** [const_ashr c1 c2] returns the constant integer [c1] right-shifted by the
1154-
constant integer [c2] with sign extension.
1155-
See the method [llvm::ConstantExpr::getAShr]. *)
1156-
val const_ashr : llvalue -> llvalue -> llvalue
1157-
11581148
(** [const_gep srcty pc indices] returns the constant [getElementPtr] of [pc]
11591149
with source element type [srcty] and the constant integers indices from the
11601150
array [indices].

llvm/bindings/ocaml/llvm/llvm_ocaml.c

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1233,18 +1233,6 @@ value llvm_const_shl(value LHS, value RHS) {
12331233
return to_val(Value);
12341234
}
12351235

1236-
/* llvalue -> llvalue -> llvalue */
1237-
value llvm_const_lshr(value LHS, value RHS) {
1238-
LLVMValueRef Value = LLVMConstLShr(Value_val(LHS), Value_val(RHS));
1239-
return to_val(Value);
1240-
}
1241-
1242-
/* llvalue -> llvalue -> llvalue */
1243-
value llvm_const_ashr(value LHS, value RHS) {
1244-
LLVMValueRef Value = LLVMConstAShr(Value_val(LHS), Value_val(RHS));
1245-
return to_val(Value);
1246-
}
1247-
12481236
/* lltype -> llvalue -> llvalue array -> llvalue */
12491237
value llvm_const_gep(value Ty, value ConstantVal, value Indices) {
12501238
mlsize_t Length = Wosize_val(Indices);

llvm/docs/LangRef.rst

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4693,10 +4693,6 @@ The following is the syntax for constant expressions:
46934693
Perform a multiplication on constants.
46944694
``shl (LHS, RHS)``
46954695
Perform a left shift on constants.
4696-
``lshr (LHS, RHS)``
4697-
Perform a logical right shift on constants.
4698-
``ashr (LHS, RHS)``
4699-
Perform an arithmetic right shift on constants.
47004696
``xor (LHS, RHS)``
47014697
Perform a bitwise xor on constants.
47024698

llvm/docs/ReleaseNotes.rst

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

5858
* ``and``
5959
* ``or``
60+
* ``lshr``
61+
* ``ashr``
6062
* ``zext``
6163
* ``sext``
6264
* ``fptrunc``
@@ -174,6 +176,8 @@ Changes to the C API
174176

175177
* ``LLVMConstAnd``
176178
* ``LLVMConstOr``
179+
* ``LLVMConstLShr``
180+
* ``LLVMConstAShr``
177181
* ``LLVMConstZExt``
178182
* ``LLVMConstSExt``
179183
* ``LLVMConstZExtOrBitCast``

llvm/include/llvm-c/Core.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2281,8 +2281,6 @@ LLVMValueRef LLVMConstICmp(LLVMIntPredicate Predicate,
22812281
LLVMValueRef LLVMConstFCmp(LLVMRealPredicate Predicate,
22822282
LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
22832283
LLVMValueRef LLVMConstShl(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
2284-
LLVMValueRef LLVMConstLShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
2285-
LLVMValueRef LLVMConstAShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
22862284
LLVMValueRef LLVMConstGEP2(LLVMTypeRef Ty, LLVMValueRef ConstantVal,
22872285
LLVMValueRef *ConstantIndices, unsigned NumIndices);
22882286
LLVMValueRef LLVMConstInBoundsGEP2(LLVMTypeRef Ty, LLVMValueRef ConstantVal,

llvm/include/llvm/IR/Constants.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1038,8 +1038,6 @@ class ConstantExpr : public Constant {
10381038
static Constant *getXor(Constant *C1, Constant *C2);
10391039
static Constant *getShl(Constant *C1, Constant *C2, bool HasNUW = false,
10401040
bool HasNSW = false);
1041-
static Constant *getLShr(Constant *C1, Constant *C2, bool isExact = false);
1042-
static Constant *getAShr(Constant *C1, Constant *C2, bool isExact = false);
10431041
static Constant *getTrunc(Constant *C, Type *Ty, bool OnlyIfReduced = false);
10441042
static Constant *getPtrToInt(Constant *C, Type *Ty,
10451043
bool OnlyIfReduced = false);
@@ -1085,14 +1083,6 @@ class ConstantExpr : public Constant {
10851083
return getShl(C1, C2, true, false);
10861084
}
10871085

1088-
static Constant *getExactAShr(Constant *C1, Constant *C2) {
1089-
return getAShr(C1, C2, true);
1090-
}
1091-
1092-
static Constant *getExactLShr(Constant *C1, Constant *C2) {
1093-
return getLShr(C1, C2, true);
1094-
}
1095-
10961086
/// If C is a scalar/fixed width vector of known powers of 2, then this
10971087
/// function returns a new scalar/fixed width vector obtained from logBase2
10981088
/// of C. Undef vector elements are set to zero.

llvm/lib/AsmParser/LLParser.cpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3852,6 +3852,10 @@ bool LLParser::parseValID(ValID &ID, PerFunctionState *PFS, Type *ExpectedTy) {
38523852
return error(ID.Loc, "and constexprs are no longer supported");
38533853
case lltok::kw_or:
38543854
return error(ID.Loc, "or constexprs are no longer supported");
3855+
case lltok::kw_lshr:
3856+
return error(ID.Loc, "lshr constexprs are no longer supported");
3857+
case lltok::kw_ashr:
3858+
return error(ID.Loc, "ashr constexprs are no longer supported");
38553859
case lltok::kw_fneg:
38563860
return error(ID.Loc, "fneg constexprs are no longer supported");
38573861
case lltok::kw_select:
@@ -3910,12 +3914,9 @@ bool LLParser::parseValID(ValID &ID, PerFunctionState *PFS, Type *ExpectedTy) {
39103914
case lltok::kw_sub:
39113915
case lltok::kw_mul:
39123916
case lltok::kw_shl:
3913-
case lltok::kw_lshr:
3914-
case lltok::kw_ashr:
39153917
case lltok::kw_xor: {
39163918
bool NUW = false;
39173919
bool NSW = false;
3918-
bool Exact = false;
39193920
unsigned Opc = Lex.getUIntVal();
39203921
Constant *Val0, *Val1;
39213922
Lex.Lex();
@@ -3928,10 +3929,6 @@ bool LLParser::parseValID(ValID &ID, PerFunctionState *PFS, Type *ExpectedTy) {
39283929
if (EatIfPresent(lltok::kw_nuw))
39293930
NUW = true;
39303931
}
3931-
} else if (Opc == Instruction::SDiv || Opc == Instruction::UDiv ||
3932-
Opc == Instruction::LShr || Opc == Instruction::AShr) {
3933-
if (EatIfPresent(lltok::kw_exact))
3934-
Exact = true;
39353932
}
39363933
if (parseToken(lltok::lparen, "expected '(' in binary constantexpr") ||
39373934
parseGlobalTypeAndValue(Val0) ||
@@ -3948,7 +3945,6 @@ bool LLParser::parseValID(ValID &ID, PerFunctionState *PFS, Type *ExpectedTy) {
39483945
unsigned Flags = 0;
39493946
if (NUW) Flags |= OverflowingBinaryOperator::NoUnsignedWrap;
39503947
if (NSW) Flags |= OverflowingBinaryOperator::NoSignedWrap;
3951-
if (Exact) Flags |= PossiblyExactOperator::IsExact;
39523948
ID.ConstantVal = ConstantExpr::get(Opc, Val0, Val1, Flags);
39533949
ID.Kind = ValID::t_Constant;
39543950
return false;

llvm/lib/IR/ConstantFold.cpp

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -155,29 +155,6 @@ static Constant *ExtractConstantBytes(Constant *C, unsigned ByteStart,
155155

156156
switch (CE->getOpcode()) {
157157
default: return nullptr;
158-
case Instruction::LShr: {
159-
ConstantInt *Amt = dyn_cast<ConstantInt>(CE->getOperand(1));
160-
if (!Amt)
161-
return nullptr;
162-
APInt ShAmt = Amt->getValue();
163-
// Cannot analyze non-byte shifts.
164-
if ((ShAmt & 7) != 0)
165-
return nullptr;
166-
ShAmt.lshrInPlace(3);
167-
168-
// If the extract is known to be all zeros, return zero.
169-
if (ShAmt.uge(CSize - ByteStart))
170-
return Constant::getNullValue(
171-
IntegerType::get(CE->getContext(), ByteSize * 8));
172-
// If the extract is known to be fully in the input, extract it.
173-
if (ShAmt.ule(CSize - (ByteStart + ByteSize)))
174-
return ExtractConstantBytes(CE->getOperand(0),
175-
ByteStart + ShAmt.getZExtValue(), ByteSize);
176-
177-
// TODO: Handle the 'partially zero' case.
178-
return nullptr;
179-
}
180-
181158
case Instruction::Shl: {
182159
ConstantInt *Amt = dyn_cast<ConstantInt>(CE->getOperand(1));
183160
if (!Amt)

llvm/lib/IR/Constants.cpp

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2160,13 +2160,13 @@ bool ConstantExpr::isSupportedBinOp(unsigned Opcode) {
21602160
case Instruction::FRem:
21612161
case Instruction::And:
21622162
case Instruction::Or:
2163+
case Instruction::LShr:
2164+
case Instruction::AShr:
21632165
return false;
21642166
case Instruction::Add:
21652167
case Instruction::Sub:
21662168
case Instruction::Mul:
21672169
case Instruction::Shl:
2168-
case Instruction::LShr:
2169-
case Instruction::AShr:
21702170
case Instruction::Xor:
21712171
return true;
21722172
default:
@@ -2482,16 +2482,6 @@ Constant *ConstantExpr::getShl(Constant *C1, Constant *C2,
24822482
return get(Instruction::Shl, C1, C2, Flags);
24832483
}
24842484

2485-
Constant *ConstantExpr::getLShr(Constant *C1, Constant *C2, bool isExact) {
2486-
return get(Instruction::LShr, C1, C2,
2487-
isExact ? PossiblyExactOperator::IsExact : 0);
2488-
}
2489-
2490-
Constant *ConstantExpr::getAShr(Constant *C1, Constant *C2, bool isExact) {
2491-
return get(Instruction::AShr, C1, C2,
2492-
isExact ? PossiblyExactOperator::IsExact : 0);
2493-
}
2494-
24952485
Constant *ConstantExpr::getExactLogBase2(Constant *C) {
24962486
Type *Ty = C->getType();
24972487
const APInt *IVal;

0 commit comments

Comments
 (0)