[llvm] [IR] Remove support for icmp and fcmp constant expressions (PR #93038)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 3 07:51:53 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-transforms
@llvm/pr-subscribers-backend-aarch64
@llvm/pr-subscribers-backend-x86
Author: Nikita Popov (nikic)
<details>
<summary>Changes</summary>
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.
---
Patch is 137.67 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/93038.diff
116 Files Affected:
- (modified) llvm/bindings/ocaml/llvm/llvm.ml (-4)
- (modified) llvm/bindings/ocaml/llvm/llvm.mli (-10)
- (modified) llvm/bindings/ocaml/llvm/llvm_ocaml.c (-12)
- (modified) llvm/docs/LangRef.rst (-4)
- (modified) llvm/docs/ReleaseNotes.rst (+13)
- (modified) llvm/include/llvm-c/Core.h (-4)
- (modified) llvm/include/llvm/IR/Constants.h (-21)
- (modified) llvm/lib/Analysis/ConstantFolding.cpp (+1-5)
- (modified) llvm/lib/AsmParser/LLParser.cpp (+3-31)
- (modified) llvm/lib/Bitcode/Reader/BitcodeReader.cpp (+2-4)
- (modified) llvm/lib/Bitcode/Writer/BitcodeWriter.cpp (-8)
- (modified) llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp (+2-4)
- (modified) llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp (+4-12)
- (modified) llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.h (+2-2)
- (modified) llvm/lib/ExecutionEngine/Interpreter/Execution.cpp (-43)
- (modified) llvm/lib/IR/AsmWriter.cpp (-2)
- (modified) llvm/lib/IR/ConstantFold.cpp (-16)
- (modified) llvm/lib/IR/Constants.cpp (+10-103)
- (modified) llvm/lib/IR/ConstantsContext.h (+6-52)
- (modified) llvm/lib/IR/Core.cpp (-20)
- (modified) llvm/lib/Target/NVPTX/NVPTXGenericToNVVM.cpp (-8)
- (modified) llvm/lib/Transforms/IPO/AttributorAttributes.cpp (+1-12)
- (modified) llvm/lib/Transforms/Utils/FunctionComparator.cpp (-3)
- (modified) llvm/test/Analysis/Lint/noop-cast-expr-no-pointer.ll (+1-1)
- (modified) llvm/test/Assembler/2007-01-05-Cmp-ConstExpr.ll (+2-1)
- (modified) llvm/test/Assembler/ConstantExprFold.ll (-10)
- (removed) llvm/test/Assembler/vector-cmp.ll (-17)
- (modified) llvm/test/Bindings/OCaml/core.ml (-2)
- (modified) llvm/test/Bitcode/vscale-round-trip.ll (+1-3)
- (modified) llvm/test/CodeGen/AArch64/addsub.ll (+9-7)
- (modified) llvm/test/CodeGen/AArch64/arm64-codegen-prepare-extload.ll (+6-3)
- (modified) llvm/test/CodeGen/AArch64/dag-combine-concat-vectors.ll (+4-1)
- (modified) llvm/test/CodeGen/AArch64/windows-extern-weak.ll (+17-3)
- (modified) llvm/test/CodeGen/AMDGPU/force-alwaysinline-lds-global-address.ll (+2-1)
- (modified) llvm/test/CodeGen/AMDGPU/loop_break.ll (+4-2)
- (modified) llvm/test/CodeGen/ARM/Windows/mov32t-bundling.ll (+2-1)
- (modified) llvm/test/CodeGen/Generic/pr33094.ll (+2-2)
- (modified) llvm/test/CodeGen/Hexagon/stack-align-reset.ll (+2-1)
- (modified) llvm/test/CodeGen/Mips/mirparser/target-flags-pic-mxgot-tls.mir (+2-1)
- (modified) llvm/test/CodeGen/Mips/mirparser/target-flags-static-tls.mir (+2-1)
- (modified) llvm/test/CodeGen/PowerPC/2008-05-01-ppc_fp128.ll (+2-1)
- (modified) llvm/test/CodeGen/PowerPC/ifcvt-forked-bug-2016-08-08.ll (+2-1)
- (modified) llvm/test/CodeGen/PowerPC/pr24636.ll (+2-1)
- (modified) llvm/test/CodeGen/PowerPC/pr3711_widen_bit.ll (+2-1)
- (modified) llvm/test/CodeGen/PowerPC/pr46923.ll (+2-2)
- (modified) llvm/test/CodeGen/PowerPC/toc-load-sched-bug.ll (+4-2)
- (modified) llvm/test/CodeGen/WebAssembly/add-prototypes.ll (+4-2)
- (modified) llvm/test/CodeGen/WebAssembly/fast-isel-noreg.ll (-28)
- (modified) llvm/test/CodeGen/X86/2008-09-19-RegAllocBug.ll (+2-1)
- (modified) llvm/test/CodeGen/X86/address-type-promotion-constantexpr.ll (+2-1)
- (modified) llvm/test/CodeGen/X86/codegen-prepare-extload.ll (+6-3)
- (modified) llvm/test/CodeGen/X86/codegen-prepare-replacephi2.mir (+1-1)
- (modified) llvm/test/CodeGen/X86/extern_weak.ll (+2-1)
- (modified) llvm/test/CodeGen/X86/fast-isel-expect.ll (+2-1)
- (modified) llvm/test/CodeGen/X86/no-plt.ll (+2-1)
- (modified) llvm/test/CodeGen/X86/pr44749.ll (+9-7)
- (modified) llvm/test/CodeGen/X86/undef-label.ll (+4-2)
- (modified) llvm/test/ExecutionEngine/MCJIT/test-constantexpr.ll (+1-2)
- (modified) llvm/test/Feature/const_pv.ll (-2)
- (modified) llvm/test/Instrumentation/DataFlowSanitizer/extern_weak.ll (+3-2)
- (modified) llvm/test/Other/constant-fold-gep.ll (+8-7)
- (modified) llvm/test/Transforms/Attributor/value-simplify.ll (-28)
- (modified) llvm/test/Transforms/CorrelatedValuePropagation/2010-09-26-MergeConstantRange.ll (+4-2)
- (modified) llvm/test/Transforms/CorrelatedValuePropagation/select.ll (+6-4)
- (modified) llvm/test/Transforms/GVN/PRE/pre-load-dbg.ll (+4-2)
- (modified) llvm/test/Transforms/GlobalDCE/complex-constantexpr.ll (+2-1)
- (modified) llvm/test/Transforms/GlobalOpt/cleanup-pointer-root-users-other-constexpr.ll (+8-6)
- (modified) llvm/test/Transforms/GlobalOpt/constantfold-initializers.ll (+2-2)
- (modified) llvm/test/Transforms/GlobalOpt/dead-constant-user.ll (+5-3)
- (modified) llvm/test/Transforms/GlobalOpt/pr61674.ll (+1-1)
- (modified) llvm/test/Transforms/IndVarSimplify/pr45835.ll (+1-1)
- (modified) llvm/test/Transforms/InferAddressSpaces/AMDGPU/infer-address-space.ll (+4-2)
- (modified) llvm/test/Transforms/Inline/always-inline.ll (+4-3)
- (modified) llvm/test/Transforms/Inline/last-callsite.ll (+5-4)
- (modified) llvm/test/Transforms/InstCombine/2004-11-27-SetCCForCastLargerAndConstant.ll (+2-1)
- (modified) llvm/test/Transforms/InstCombine/2008-05-18-FoldIntToPtr.ll (+4-2)
- (modified) llvm/test/Transforms/InstCombine/2010-03-03-ExtElim.ll (+4-2)
- (modified) llvm/test/Transforms/InstCombine/2012-3-15-or-xor-constant.ll (+2-1)
- (modified) llvm/test/Transforms/InstCombine/binop-select-cast-of-select-cond.ll (+5-3)
- (modified) llvm/test/Transforms/InstCombine/cast.ll (+2-1)
- (modified) llvm/test/Transforms/InstCombine/constant-fold-compare.ll (+2-1)
- (modified) llvm/test/Transforms/InstCombine/constant-fold-iteration.ll (+2-1)
- (modified) llvm/test/Transforms/InstCombine/fold-bin-operand.ll (+6-3)
- (modified) llvm/test/Transforms/InstCombine/icmp-bitcast-glob.ll (+2-1)
- (modified) llvm/test/Transforms/InstCombine/icmp-mul.ll (+2-1)
- (modified) llvm/test/Transforms/InstCombine/mul-inseltpoison.ll (+4-2)
- (modified) llvm/test/Transforms/InstCombine/mul.ll (+4-2)
- (modified) llvm/test/Transforms/InstCombine/not-add.ll (+2-1)
- (modified) llvm/test/Transforms/InstCombine/phi-select-constant.ll (+4-2)
- (modified) llvm/test/Transforms/InstCombine/pr20678.ll (+2-1)
- (modified) llvm/test/Transforms/InstCombine/pr28725.ll (+2-1)
- (modified) llvm/test/Transforms/InstCombine/pr32686.ll (+6-5)
- (modified) llvm/test/Transforms/InstCombine/pr33453.ll (+5-3)
- (modified) llvm/test/Transforms/InstCombine/pr35515.ll (+2-1)
- (modified) llvm/test/Transforms/InstCombine/pr38677.ll (+2-1)
- (modified) llvm/test/Transforms/InstCombine/pr83947.ll (+4-4)
- (modified) llvm/test/Transforms/InstCombine/rem.ll (+10-6)
- (modified) llvm/test/Transforms/InstCombine/select-and-or.ll (+12-5)
- (modified) llvm/test/Transforms/InstCombine/select-safe-transforms.ll (+4-4)
- (modified) llvm/test/Transforms/InstCombine/select.ll (+2-2)
- (modified) llvm/test/Transforms/InstCombine/shift-amount-reassociation-in-bittest.ll (+8-6)
- (modified) llvm/test/Transforms/InstCombine/vec_demanded_elts-inseltpoison.ll (+3-3)
- (modified) llvm/test/Transforms/InstCombine/vec_demanded_elts.ll (+3-3)
- (modified) llvm/test/Transforms/InstSimplify/ConstProp/constant-expr.ll (-28)
- (modified) llvm/test/Transforms/InstSimplify/pr28725.ll (+4-2)
- (modified) llvm/test/Transforms/LowerTypeTests/function-weak.ll (+6-6)
- (modified) llvm/test/Transforms/MergeFunc/constexpr.ll (-14)
- (modified) llvm/test/Transforms/OpenMP/value-simplify-openmp-opt.ll (+4-2)
- (modified) llvm/test/Transforms/SCCP/ip-ranges-select.ll (+2-4)
- (modified) llvm/test/Transforms/SCCP/undef-resolve.ll (+4-2)
- (modified) llvm/test/Transforms/SLPVectorizer/X86/phi3.ll (+8-4)
- (modified) llvm/test/Transforms/SimplifyCFG/2009-05-12-externweak.ll (+4-2)
- (removed) llvm/test/Transforms/SimplifyCFG/phi-to-select-constexpr-icmp.ll (-23)
- (modified) llvm/test/Transforms/StructurizeCFG/invert-constantexpr.ll (+5-5)
- (modified) llvm/tools/llvm-diff/lib/DifferenceEngine.cpp (-6)
- (modified) llvm/unittests/IR/ConstantsTest.cpp (-3)
``````````diff
diff --git a/llvm/bindings/ocaml/llvm/llvm.ml b/llvm/bindings/ocaml/llvm/llvm.ml
index 003fd750cd9f8..7eeaae49e1059 100644
--- a/llvm/bindings/ocaml/llvm/llvm.ml
+++ b/llvm/bindings/ocaml/llvm/llvm.ml
@@ -651,10 +651,6 @@ external const_mul : llvalue -> llvalue -> llvalue = "llvm_const_mul"
external const_nsw_mul : llvalue -> llvalue -> llvalue = "llvm_const_nsw_mul"
external const_nuw_mul : llvalue -> llvalue -> llvalue = "llvm_const_nuw_mul"
external const_xor : llvalue -> llvalue -> llvalue = "llvm_const_xor"
-external const_icmp : Icmp.t -> llvalue -> llvalue -> llvalue
- = "llvm_const_icmp"
-external const_fcmp : Fcmp.t -> llvalue -> llvalue -> llvalue
- = "llvm_const_fcmp"
external const_shl : llvalue -> llvalue -> llvalue = "llvm_const_shl"
external const_gep : lltype -> llvalue -> llvalue array -> llvalue
= "llvm_const_gep"
diff --git a/llvm/bindings/ocaml/llvm/llvm.mli b/llvm/bindings/ocaml/llvm/llvm.mli
index 93540c619efba..36cc095dc66e3 100644
--- a/llvm/bindings/ocaml/llvm/llvm.mli
+++ b/llvm/bindings/ocaml/llvm/llvm.mli
@@ -1136,16 +1136,6 @@ val const_nuw_mul : llvalue -> llvalue -> llvalue
See the method [llvm::ConstantExpr::getXor]. *)
val const_xor : llvalue -> llvalue -> llvalue
-(** [const_icmp pred c1 c2] returns the constant comparison of two integer
- constants, [c1 pred c2].
- See the method [llvm::ConstantExpr::getICmp]. *)
-val const_icmp : Icmp.t -> llvalue -> llvalue -> llvalue
-
-(** [const_fcmp pred c1 c2] returns the constant comparison of two floating
- point constants, [c1 pred c2].
- See the method [llvm::ConstantExpr::getFCmp]. *)
-val const_fcmp : Fcmp.t -> llvalue -> llvalue -> llvalue
-
(** [const_shl c1 c2] returns the constant integer [c1] left-shifted by the
constant integer [c2].
See the method [llvm::ConstantExpr::getShl]. *)
diff --git a/llvm/bindings/ocaml/llvm/llvm_ocaml.c b/llvm/bindings/ocaml/llvm/llvm_ocaml.c
index 6d08d78b84455..26a3ac21501d2 100644
--- a/llvm/bindings/ocaml/llvm/llvm_ocaml.c
+++ b/llvm/bindings/ocaml/llvm/llvm_ocaml.c
@@ -1224,18 +1224,6 @@ value llvm_const_xor(value LHS, value RHS) {
return to_val(Value);
}
-/* Icmp.t -> llvalue -> llvalue -> llvalue */
-value llvm_const_icmp(value Pred, value LHSConstant, value RHSConstant) {
- return to_val(LLVMConstICmp(Int_val(Pred) + LLVMIntEQ, Value_val(LHSConstant),
- Value_val(RHSConstant)));
-}
-
-/* Fcmp.t -> llvalue -> llvalue -> llvalue */
-value llvm_const_fcmp(value Pred, value LHSConstant, value RHSConstant) {
- return to_val(LLVMConstFCmp(Int_val(Pred), Value_val(LHSConstant),
- Value_val(RHSConstant)));
-}
-
/* llvalue -> llvalue -> llvalue */
value llvm_const_shl(value LHS, value RHS) {
LLVMValueRef Value = LLVMConstShl(Value_val(LHS), Value_val(RHS));
diff --git a/llvm/docs/LangRef.rst b/llvm/docs/LangRef.rst
index c58f7f7140e47..494ee22ec6352 100644
--- a/llvm/docs/LangRef.rst
+++ b/llvm/docs/LangRef.rst
@@ -4821,10 +4821,6 @@ The following is the syntax for constant expressions:
required to make sense for the type of "pointer to TY". These indexes
may be implicitly sign-extended or truncated to match the index size
of CSTPTR's address space.
-``icmp COND (VAL1, VAL2)``
- Perform the :ref:`icmp operation <i_icmp>` on constants.
-``fcmp COND (VAL1, VAL2)``
- Perform the :ref:`fcmp operation <i_fcmp>` on constants.
``extractelement (VAL, IDX)``
Perform the :ref:`extractelement operation <i_extractelement>` on
constants.
diff --git a/llvm/docs/ReleaseNotes.rst b/llvm/docs/ReleaseNotes.rst
index 32ec26bf1dcb2..393b97efa5470 100644
--- a/llvm/docs/ReleaseNotes.rst
+++ b/llvm/docs/ReleaseNotes.rst
@@ -56,6 +56,11 @@ Changes to the LLVM IR
* Renamed ``llvm.experimental.vector.splice`` intrinsic to ``llvm.vector.splice``.
* Renamed ``llvm.experimental.vector.interleave2`` intrinsic to ``llvm.vector.interleave2``.
* Renamed ``llvm.experimental.vector.deinterleave2`` intrinsic to ``llvm.vector.deinterleave2``.
+* The constant expression variants of the following instructions have been
+ removed:
+
+ * ``icmp``
+ * ``fcmp``
Changes to LLVM infrastructure
------------------------------
@@ -191,6 +196,14 @@ Changes to the C API
* ``LLVMGetCallBrNumIndirectDests``
* ``LLVMGetCallBrIndirectDest``
+* The following functions for creating constant expressions have been removed,
+ because the underlying constant expressions are no longer supported. Instead,
+ an instruction should be created using the ``LLVMBuildXYZ`` APIs, which will
+ constant fold the operands if possible and create an instruction otherwise:
+
+ * ``LLVMConstICmp``
+ * ``LLVMConstFCmp``
+
Changes to the CodeGen infrastructure
-------------------------------------
diff --git a/llvm/include/llvm-c/Core.h b/llvm/include/llvm-c/Core.h
index 9d09546513f0e..9ce56b7e28a37 100644
--- a/llvm/include/llvm-c/Core.h
+++ b/llvm/include/llvm-c/Core.h
@@ -2354,10 +2354,6 @@ LLVMValueRef LLVMConstMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
LLVMValueRef LLVMConstNSWMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
LLVMValueRef LLVMConstNUWMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
LLVMValueRef LLVMConstXor(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
-LLVMValueRef LLVMConstICmp(LLVMIntPredicate Predicate,
- LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
-LLVMValueRef LLVMConstFCmp(LLVMRealPredicate Predicate,
- LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
LLVMValueRef LLVMConstShl(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
LLVMValueRef LLVMConstGEP2(LLVMTypeRef Ty, LLVMValueRef ConstantVal,
LLVMValueRef *ConstantIndices, unsigned NumIndices);
diff --git a/llvm/include/llvm/IR/Constants.h b/llvm/include/llvm/IR/Constants.h
index 86f6be7985a23..0ccccab9721c7 100644
--- a/llvm/include/llvm/IR/Constants.h
+++ b/llvm/include/llvm/IR/Constants.h
@@ -1234,9 +1234,6 @@ class ConstantExpr : public Constant {
/// Return true if this is a convert constant expression
bool isCast() const;
- /// Return true if this is a compare constant expression
- bool isCompare() const;
-
/// get - Return a binary or shift operator constant expression,
/// folding if possible.
///
@@ -1244,20 +1241,6 @@ class ConstantExpr : public Constant {
static Constant *get(unsigned Opcode, Constant *C1, Constant *C2,
unsigned Flags = 0, Type *OnlyIfReducedTy = nullptr);
- /// Return an ICmp or FCmp comparison operator constant expression.
- ///
- /// \param OnlyIfReduced see \a getWithOperands() docs.
- static Constant *getCompare(unsigned short pred, Constant *C1, Constant *C2,
- bool OnlyIfReduced = false);
-
- /// get* - Return some common constants without having to
- /// specify the full Instruction::OPCODE identifier.
- ///
- static Constant *getICmp(unsigned short pred, Constant *LHS, Constant *RHS,
- bool OnlyIfReduced = false);
- static Constant *getFCmp(unsigned short pred, Constant *LHS, Constant *RHS,
- bool OnlyIfReduced = false);
-
/// Getelementptr form. Value* is only accepted for convenience;
/// all elements must be Constants.
///
@@ -1318,10 +1301,6 @@ class ConstantExpr : public Constant {
/// Return the opcode at the root of this constant expression
unsigned getOpcode() const { return getSubclassDataFromValue(); }
- /// Return the ICMP or FCMP predicate value. Assert if this is not an ICMP or
- /// FCMP constant expression.
- unsigned getPredicate() const;
-
/// Assert that this is a shufflevector and return the mask. See class
/// ShuffleVectorInst for a description of the mask representation.
ArrayRef<int> getShuffleMask() const;
diff --git a/llvm/lib/Analysis/ConstantFolding.cpp b/llvm/lib/Analysis/ConstantFolding.cpp
index 0fc7bf238a11d..0cb35c4e0290e 100644
--- a/llvm/lib/Analysis/ConstantFolding.cpp
+++ b/llvm/lib/Analysis/ConstantFolding.cpp
@@ -1009,12 +1009,8 @@ Constant *ConstantFoldInstOperandsImpl(const Value *InstOrCE, unsigned Opcode,
GEP->getInRange());
}
- if (auto *CE = dyn_cast<ConstantExpr>(InstOrCE)) {
- if (CE->isCompare())
- return ConstantFoldCompareInstOperands(CE->getPredicate(), Ops[0], Ops[1],
- DL, TLI);
+ if (auto *CE = dyn_cast<ConstantExpr>(InstOrCE))
return CE->getWithOperands(Ops);
- }
switch (Opcode) {
default: return nullptr;
diff --git a/llvm/lib/AsmParser/LLParser.cpp b/llvm/lib/AsmParser/LLParser.cpp
index df0827996396e..07c8aa23fc5e2 100644
--- a/llvm/lib/AsmParser/LLParser.cpp
+++ b/llvm/lib/AsmParser/LLParser.cpp
@@ -4176,37 +4176,9 @@ bool LLParser::parseValID(ValID &ID, PerFunctionState *PFS, Type *ExpectedTy) {
case lltok::kw_fptosi:
return error(ID.Loc, "fptosi constexprs are no longer supported");
case lltok::kw_icmp:
- case lltok::kw_fcmp: {
- unsigned PredVal, Opc = Lex.getUIntVal();
- Constant *Val0, *Val1;
- Lex.Lex();
- if (parseCmpPredicate(PredVal, Opc) ||
- parseToken(lltok::lparen, "expected '(' in compare constantexpr") ||
- parseGlobalTypeAndValue(Val0) ||
- parseToken(lltok::comma, "expected comma in compare constantexpr") ||
- parseGlobalTypeAndValue(Val1) ||
- parseToken(lltok::rparen, "expected ')' in compare constantexpr"))
- return true;
-
- if (Val0->getType() != Val1->getType())
- return error(ID.Loc, "compare operands must have the same type");
-
- CmpInst::Predicate Pred = (CmpInst::Predicate)PredVal;
-
- if (Opc == Instruction::FCmp) {
- if (!Val0->getType()->isFPOrFPVectorTy())
- return error(ID.Loc, "fcmp requires floating point operands");
- ID.ConstantVal = ConstantExpr::getFCmp(Pred, Val0, Val1);
- } else {
- assert(Opc == Instruction::ICmp && "Unexpected opcode for CmpInst!");
- if (!Val0->getType()->isIntOrIntVectorTy() &&
- !Val0->getType()->isPtrOrPtrVectorTy())
- return error(ID.Loc, "icmp requires pointer or integer operands");
- ID.ConstantVal = ConstantExpr::getICmp(Pred, Val0, Val1);
- }
- ID.Kind = ValID::t_Constant;
- return false;
- }
+ return error(ID.Loc, "icmp constexprs are no longer supported");
+ case lltok::kw_fcmp:
+ return error(ID.Loc, "fcmp constexprs are no longer supported");
// Binary Operators.
case lltok::kw_add:
diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
index aee627bbde0bf..8519796deeb1a 100644
--- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
+++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
@@ -1495,6 +1495,8 @@ static bool isConstExprSupported(const BitcodeConstant *BC) {
switch (Opcode) {
case Instruction::FNeg:
case Instruction::Select:
+ case Instruction::ICmp:
+ case Instruction::FCmp:
return false;
default:
return true;
@@ -1633,10 +1635,6 @@ Expected<Value *> BitcodeReader::materializeValue(unsigned StartValID,
case BitcodeConstant::ConstantVectorOpcode:
C = ConstantVector::get(ConstOps);
break;
- case Instruction::ICmp:
- case Instruction::FCmp:
- C = ConstantExpr::getCompare(BC->Flags, ConstOps[0], ConstOps[1]);
- break;
case Instruction::GetElementPtr:
C = ConstantExpr::getGetElementPtr(
BC->SrcElemTy, ConstOps[0], ArrayRef(ConstOps).drop_front(),
diff --git a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
index 7d39c0db79fb1..65e5052dbb4da 100644
--- a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
+++ b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
@@ -2822,14 +2822,6 @@ void ModuleBitcodeWriter::writeConstants(unsigned FirstVal, unsigned LastVal,
Record.push_back(VE.getValueID(C->getOperand(1)));
Record.push_back(VE.getValueID(CE->getShuffleMaskForBitcode()));
break;
- case Instruction::ICmp:
- case Instruction::FCmp:
- Code = bitc::CST_CODE_CE_CMP;
- Record.push_back(VE.getTypeID(C->getOperand(0)->getType()));
- Record.push_back(VE.getValueID(C->getOperand(0)));
- Record.push_back(VE.getValueID(C->getOperand(1)));
- Record.push_back(CE->getPredicate());
- break;
}
} else if (const BlockAddress *BA = dyn_cast<BlockAddress>(C)) {
Code = bitc::CST_CODE_BLOCKADDRESS;
diff --git a/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp b/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
index 67c51f018a807..25b14c860284d 100644
--- a/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
+++ b/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
@@ -335,13 +335,11 @@ bool IRTranslator::translateFNeg(const User &U, MachineIRBuilder &MIRBuilder) {
bool IRTranslator::translateCompare(const User &U,
MachineIRBuilder &MIRBuilder) {
- auto *CI = dyn_cast<CmpInst>(&U);
+ auto *CI = cast<CmpInst>(&U);
Register Op0 = getOrCreateVReg(*U.getOperand(0));
Register Op1 = getOrCreateVReg(*U.getOperand(1));
Register Res = getOrCreateVReg(U);
- CmpInst::Predicate Pred =
- CI ? CI->getPredicate() : static_cast<CmpInst::Predicate>(
- cast<ConstantExpr>(U).getPredicate());
+ CmpInst::Predicate Pred = CI->getPredicate();
if (CmpInst::isIntPredicate(Pred))
MIRBuilder.buildICmp(Pred, Res, Op0, Op1);
else if (Pred == CmpInst::FCMP_FALSE)
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
index c7e0c62ec1263..f98bf48a2c3e0 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
@@ -3617,12 +3617,8 @@ void SelectionDAGBuilder::visitSDiv(const User &I) {
Op2, Flags));
}
-void SelectionDAGBuilder::visitICmp(const User &I) {
- ICmpInst::Predicate predicate = ICmpInst::BAD_ICMP_PREDICATE;
- if (const ICmpInst *IC = dyn_cast<ICmpInst>(&I))
- predicate = IC->getPredicate();
- else if (const ConstantExpr *IC = dyn_cast<ConstantExpr>(&I))
- predicate = ICmpInst::Predicate(IC->getPredicate());
+void SelectionDAGBuilder::visitICmp(const ICmpInst &I) {
+ ICmpInst::Predicate predicate = I.getPredicate();
SDValue Op1 = getValue(I.getOperand(0));
SDValue Op2 = getValue(I.getOperand(1));
ISD::CondCode Opcode = getICmpCondCode(predicate);
@@ -3644,12 +3640,8 @@ void SelectionDAGBuilder::visitICmp(const User &I) {
setValue(&I, DAG.getSetCC(getCurSDLoc(), DestVT, Op1, Op2, Opcode));
}
-void SelectionDAGBuilder::visitFCmp(const User &I) {
- FCmpInst::Predicate predicate = FCmpInst::BAD_FCMP_PREDICATE;
- if (const FCmpInst *FC = dyn_cast<FCmpInst>(&I))
- predicate = FC->getPredicate();
- else if (const ConstantExpr *FC = dyn_cast<ConstantExpr>(&I))
- predicate = FCmpInst::Predicate(FC->getPredicate());
+void SelectionDAGBuilder::visitFCmp(const FCmpInst &I) {
+ FCmpInst::Predicate predicate = I.getPredicate();
SDValue Op1 = getValue(I.getOperand(0));
SDValue Op2 = getValue(I.getOperand(1));
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.h b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.h
index 6cb2c78a547ac..1a98fbd7589fb 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.h
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.h
@@ -563,8 +563,8 @@ class SelectionDAGBuilder {
void visitShl (const User &I) { visitShift(I, ISD::SHL); }
void visitLShr(const User &I) { visitShift(I, ISD::SRL); }
void visitAShr(const User &I) { visitShift(I, ISD::SRA); }
- void visitICmp(const User &I);
- void visitFCmp(const User &I);
+ void visitICmp(const ICmpInst &I);
+ void visitFCmp(const FCmpInst &I);
// Visit the conversion instructions
void visitTrunc(const User &I);
void visitZExt(const User &I);
diff --git a/llvm/lib/ExecutionEngine/Interpreter/Execution.cpp b/llvm/lib/ExecutionEngine/Interpreter/Execution.cpp
index 64536dd5a9137..2d69edef878e6 100644
--- a/llvm/lib/ExecutionEngine/Interpreter/Execution.cpp
+++ b/llvm/lib/ExecutionEngine/Interpreter/Execution.cpp
@@ -697,42 +697,6 @@ void Interpreter::visitFCmpInst(FCmpInst &I) {
SetValue(&I, R, SF);
}
-static GenericValue executeCmpInst(unsigned predicate, GenericValue Src1,
- GenericValue Src2, Type *Ty) {
- GenericValue Result;
- switch (predicate) {
- case ICmpInst::ICMP_EQ: return executeICMP_EQ(Src1, Src2, Ty);
- case ICmpInst::ICMP_NE: return executeICMP_NE(Src1, Src2, Ty);
- case ICmpInst::ICMP_UGT: return executeICMP_UGT(Src1, Src2, Ty);
- case ICmpInst::ICMP_SGT: return executeICMP_SGT(Src1, Src2, Ty);
- case ICmpInst::ICMP_ULT: return executeICMP_ULT(Src1, Src2, Ty);
- case ICmpInst::ICMP_SLT: return executeICMP_SLT(Src1, Src2, Ty);
- case ICmpInst::ICMP_UGE: return executeICMP_UGE(Src1, Src2, Ty);
- case ICmpInst::ICMP_SGE: return executeICMP_SGE(Src1, Src2, Ty);
- case ICmpInst::ICMP_ULE: return executeICMP_ULE(Src1, Src2, Ty);
- case ICmpInst::ICMP_SLE: return executeICMP_SLE(Src1, Src2, Ty);
- case FCmpInst::FCMP_ORD: return executeFCMP_ORD(Src1, Src2, Ty);
- case FCmpInst::FCMP_UNO: return executeFCMP_UNO(Src1, Src2, Ty);
- case FCmpInst::FCMP_OEQ: return executeFCMP_OEQ(Src1, Src2, Ty);
- case FCmpInst::FCMP_UEQ: return executeFCMP_UEQ(Src1, Src2, Ty);
- case FCmpInst::FCMP_ONE: return executeFCMP_ONE(Src1, Src2, Ty);
- case FCmpInst::FCMP_UNE: return executeFCMP_UNE(Src1, Src2, Ty);
- case FCmpInst::FCMP_OLT: return executeFCMP_OLT(Src1, Src2, Ty);
- case FCmpInst::FCMP_ULT: return executeFCMP_ULT(Src1, Src2, Ty);
- case FCmpInst::FCMP_OGT: return executeFCMP_OGT(Src1, Src2, Ty);
- case FCmpInst::FCMP_UGT: return executeFCMP_UGT(Src1, Src2, Ty);
- case FCmpInst::FCMP_OLE: return executeFCMP_OLE(Src1, Src2, Ty);
- case FCmpInst::FCMP_ULE: return executeFCMP_ULE(Src1, Src2, Ty);
- case FCmpInst::FCMP_OGE: return executeFCMP_OGE(Src1, Src2, Ty);
- case FCmpInst::FCMP_UGE: return executeFCMP_UGE(Src1, Src2, Ty);
- case FCmpInst::FCMP_FALSE: return executeFCMP_BOOL(Src1, Src2, Ty, false);
- case FCmpInst::FCMP_TRUE: return executeFCMP_BOOL(Src1, Src2, Ty, true);
- default:
- dbgs() << "Unhandled Cmp predicate\n";
- llvm_unreachable(nullptr);
- }
-}
-
void Interpreter::visitBinaryOperator(BinaryOperator &I) {
ExecutionContext &SF = ECStack.back();
Type *Ty = I.getOperand(0)->getType();
@@ -2028,13 +1992,6 @@ GenericValue Interpreter::getConstantExprValue (ConstantExpr *CE,
case Instruction::GetElementPtr:
return executeGEPOperation(CE->getOperand(0), gep_type_begin(CE),
gep_type_end(CE), SF);
- case Instruction::FCmp:
- case Instruction::ICmp:
- return executeCmpInst(CE->getPredicate(),
- getOperandValue(CE->getOperand(0), SF),
- getOperandValue(CE->getOperand(1), SF),
- CE->getOperand(0)->getType());
- default:
break;
}
diff --git a/llvm/lib/IR/AsmWriter.cpp b/llvm/lib/IR/AsmWriter.cpp
index 8b1a21f962b08..7a5f18fe2cbd5 100644
--- a/llvm/lib/IR/AsmWriter.cpp
+++ b/llvm/lib/IR/AsmWriter.cpp
@@ -1724,8 +1724,6 @@ static void WriteConstantInternal(raw_ostream &Out, const Constant *CV,
if (const ConstantExpr *CE = dyn_cast<ConstantExpr>(CV)) {
Out << CE->getOpcodeName();
WriteOptimizationInfo(Out, CE);
- if (CE->isCompare())
- Out << ' ' << static_cast<CmpInst::Predicate>(CE->getPredicate());
Out << " (";
if (const GEPOperator *GEP = dyn_cast<GEPOperator>(CE)) {
diff --git a/llvm/lib/IR/ConstantFold.cpp b/llvm/lib/IR/ConstantFold.cpp
index 0ef92ea06b411..7b8b9a7b652da 100644
--- a/llvm/lib/IR/ConstantFold.cpp
+++ b/llvm/lib/IR/ConstantFold.cpp
@@ -863,22 +863,6 @@ Constant *llvm::ConstantFoldBinaryInstruction(unsigned Opcode, Constant *C1,
if (CI2->isMinusOne())
return C2; // X | -1 == -1
break;
- case Instruction::Xor:
- if (ConstantExpr *CE1 = dyn_cast<ConstantExpr>(C1)) {
- switch (CE1->getOpcode()) {
- default:
- break;
- case Instruction::ICmp...
[truncated]
``````````
</details>
https://github.com/llvm/llvm-project/pull/93038
More information about the llvm-commits
mailing list