diff --git a/llvm/bindings/go/llvm/ir.go b/llvm/bindings/go/llvm/ir.go --- a/llvm/bindings/go/llvm/ir.go +++ b/llvm/bindings/go/llvm/ir.go @@ -904,7 +904,6 @@ func ConstNeg(v Value) (rv Value) { rv.C = C.LLVMConstNeg(v.C); return } func ConstNSWNeg(v Value) (rv Value) { rv.C = C.LLVMConstNSWNeg(v.C); return } func ConstNUWNeg(v Value) (rv Value) { rv.C = C.LLVMConstNUWNeg(v.C); return } -func ConstFNeg(v Value) (rv Value) { rv.C = C.LLVMConstFNeg(v.C); return } func ConstNot(v Value) (rv Value) { rv.C = C.LLVMConstNot(v.C); return } func ConstAdd(lhs, rhs Value) (v Value) { v.C = C.LLVMConstAdd(lhs.C, rhs.C); return } func ConstNSWAdd(lhs, rhs Value) (v Value) { v.C = C.LLVMConstNSWAdd(lhs.C, rhs.C); return } diff --git a/llvm/bindings/ocaml/llvm/llvm.ml b/llvm/bindings/ocaml/llvm/llvm.ml --- a/llvm/bindings/ocaml/llvm/llvm.ml +++ b/llvm/bindings/ocaml/llvm/llvm.ml @@ -637,7 +637,6 @@ external const_neg : llvalue -> llvalue = "LLVMConstNeg" external const_nsw_neg : llvalue -> llvalue = "LLVMConstNSWNeg" external const_nuw_neg : llvalue -> llvalue = "LLVMConstNUWNeg" -external const_fneg : llvalue -> llvalue = "LLVMConstFNeg" external const_not : llvalue -> llvalue = "LLVMConstNot" external const_add : llvalue -> llvalue -> llvalue = "LLVMConstAdd" external const_nsw_add : llvalue -> llvalue -> llvalue = "LLVMConstNSWAdd" diff --git a/llvm/bindings/ocaml/llvm/llvm.mli b/llvm/bindings/ocaml/llvm/llvm.mli --- a/llvm/bindings/ocaml/llvm/llvm.mli +++ b/llvm/bindings/ocaml/llvm/llvm.mli @@ -1077,10 +1077,6 @@ See the method [llvm::ConstantExpr::getNUWNeg]. *) val const_nuw_neg : llvalue -> llvalue -(** [const_fneg c] returns the arithmetic negation of the constant float [c]. - See the method [llvm::ConstantExpr::getFNeg]. *) -val const_fneg : llvalue -> llvalue - (** [const_not c] returns the bitwise inverse of the constant [c]. See the method [llvm::ConstantExpr::getNot]. *) val const_not : llvalue -> llvalue diff --git a/llvm/docs/ReleaseNotes.rst b/llvm/docs/ReleaseNotes.rst --- a/llvm/docs/ReleaseNotes.rst +++ b/llvm/docs/ReleaseNotes.rst @@ -62,6 +62,11 @@ Changes to the LLVM IR ---------------------- +* The constant expression variants of the following instructions have been + removed: + + * ``fneg`` + Changes to building LLVM ------------------------ @@ -126,6 +131,13 @@ Changes to the C API -------------------- +* 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: + + * ``LLVMConstFNeg`` + Changes to the Go bindings -------------------------- diff --git a/llvm/include/llvm-c/Core.h b/llvm/include/llvm-c/Core.h --- a/llvm/include/llvm-c/Core.h +++ b/llvm/include/llvm-c/Core.h @@ -2162,7 +2162,6 @@ LLVMValueRef LLVMConstNeg(LLVMValueRef ConstantVal); LLVMValueRef LLVMConstNSWNeg(LLVMValueRef ConstantVal); LLVMValueRef LLVMConstNUWNeg(LLVMValueRef ConstantVal); -LLVMValueRef LLVMConstFNeg(LLVMValueRef ConstantVal); LLVMValueRef LLVMConstNot(LLVMValueRef ConstantVal); LLVMValueRef LLVMConstAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); LLVMValueRef LLVMConstNSWAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); diff --git a/llvm/include/llvm/IR/Constants.h b/llvm/include/llvm/IR/Constants.h --- a/llvm/include/llvm/IR/Constants.h +++ b/llvm/include/llvm/IR/Constants.h @@ -1013,7 +1013,6 @@ static Constant *getNeg(Constant *C, bool HasNUW = false, bool HasNSW = false); - static Constant *getFNeg(Constant *C); static Constant *getNot(Constant *C); static Constant *getAdd(Constant *C1, Constant *C2, bool HasNUW = false, bool HasNSW = false); @@ -1190,13 +1189,6 @@ static Constant *getSelect(Constant *C, Constant *V1, Constant *V2, Type *OnlyIfReducedTy = nullptr); - /// get - Return a unary operator constant expression, - /// folding if possible. - /// - /// \param OnlyIfReducedTy see \a getWithOperands() docs. - static Constant *get(unsigned Opcode, Constant *C1, unsigned Flags = 0, - Type *OnlyIfReducedTy = nullptr); - /// get - Return a binary or shift operator constant expression, /// folding if possible. /// diff --git a/llvm/lib/AsmParser/LLParser.cpp b/llvm/lib/AsmParser/LLParser.cpp --- a/llvm/lib/AsmParser/LLParser.cpp +++ b/llvm/lib/AsmParser/LLParser.cpp @@ -3499,6 +3499,8 @@ return error(ID.Loc, "fdiv constexprs are no longer supported"); case lltok::kw_frem: return error(ID.Loc, "frem constexprs are no longer supported"); + case lltok::kw_fneg: + return error(ID.Loc, "fneg constexprs are no longer supported"); case lltok::kw_icmp: case lltok::kw_fcmp: { unsigned PredVal, Opc = Lex.getUIntVal(); @@ -3532,30 +3534,6 @@ return false; } - // Unary Operators. - case lltok::kw_fneg: { - unsigned Opc = Lex.getUIntVal(); - Constant *Val; - Lex.Lex(); - if (parseToken(lltok::lparen, "expected '(' in unary constantexpr") || - parseGlobalTypeAndValue(Val) || - parseToken(lltok::rparen, "expected ')' in unary constantexpr")) - return true; - - // Check that the type is valid for the operator. - switch (Opc) { - case Instruction::FNeg: - if (!Val->getType()->isFPOrFPVectorTy()) - return error(ID.Loc, "constexpr requires fp operands"); - break; - default: llvm_unreachable("Unknown unary operator!"); - } - unsigned Flags = 0; - Constant *C = ConstantExpr::get(Opc, Val, Flags); - ID.ConstantVal = C; - ID.Kind = ValID::t_Constant; - return false; - } // Binary Operators. case lltok::kw_add: case lltok::kw_sub: diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp --- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp @@ -1385,10 +1385,15 @@ if (Opcode >= BitcodeConstant::FirstSpecialOpcode) return true; + // If -expand-constant-exprs is set, we want to consider all expressions + // as unsupported. + if (ExpandConstantExprs) + return false; + if (Instruction::isBinaryOp(Opcode)) return ConstantExpr::isSupportedBinOp(Opcode); - return !ExpandConstantExprs; + return Opcode != Instruction::FNeg; } Expected BitcodeReader::materializeValue(unsigned StartValID, @@ -1449,8 +1454,6 @@ C = UpgradeBitCastExpr(BC->Opcode, ConstOps[0], BC->getType()); if (!C) C = ConstantExpr::getCast(BC->Opcode, ConstOps[0], BC->getType()); - } else if (Instruction::isUnaryOp(BC->Opcode)) { - C = ConstantExpr::get(BC->Opcode, ConstOps[0], BC->Flags); } else if (Instruction::isBinaryOp(BC->Opcode)) { C = ConstantExpr::get(BC->Opcode, ConstOps[0], ConstOps[1], BC->Flags); } else { diff --git a/llvm/lib/IR/Constants.cpp b/llvm/lib/IR/Constants.cpp --- a/llvm/lib/IR/Constants.cpp +++ b/llvm/lib/IR/Constants.cpp @@ -535,8 +535,8 @@ delete static_cast(C); break; case Constant::ConstantExprVal: - if (isa(C)) - delete static_cast(C); + if (isa(C)) + delete static_cast(C); else if (isa(C)) delete static_cast(C); else if (isa(C)) @@ -1484,8 +1484,6 @@ OnlyIfReducedTy); case Instruction::ExtractElement: return ConstantExpr::getExtractElement(Ops[0], Ops[1], OnlyIfReducedTy); - case Instruction::FNeg: - return ConstantExpr::getFNeg(Ops[0]); case Instruction::ShuffleVector: return ConstantExpr::getShuffleVector(Ops[0], Ops[1], getShuffleMask(), OnlyIfReducedTy); @@ -2230,37 +2228,6 @@ return getFoldedCast(Instruction::AddrSpaceCast, C, DstTy, OnlyIfReduced); } -Constant *ConstantExpr::get(unsigned Opcode, Constant *C, unsigned Flags, - Type *OnlyIfReducedTy) { - // Check the operands for consistency first. - assert(Instruction::isUnaryOp(Opcode) && - "Invalid opcode in unary constant expression"); - -#ifndef NDEBUG - switch (Opcode) { - case Instruction::FNeg: - assert(C->getType()->isFPOrFPVectorTy() && - "Tried to create a floating-point operation on a " - "non-floating-point type!"); - break; - default: - break; - } -#endif - - if (Constant *FC = ConstantFoldUnaryInstruction(Opcode, C)) - return FC; - - if (OnlyIfReducedTy == C->getType()) - return nullptr; - - Constant *ArgVec[] = { C }; - ConstantExprKeyType Key(Opcode, ArgVec, 0, Flags); - - LLVMContextImpl *pImpl = C->getContext().pImpl; - return pImpl->ExprConstants.getOrCreate(C->getType(), Key); -} - Constant *ConstantExpr::get(unsigned Opcode, Constant *C1, Constant *C2, unsigned Flags, Type *OnlyIfReducedTy) { // Check the operands for consistency first. @@ -2649,12 +2616,6 @@ C, HasNUW, HasNSW); } -Constant *ConstantExpr::getFNeg(Constant *C) { - assert(C->getType()->isFPOrFPVectorTy() && - "Cannot FNEG a non-floating-point value!"); - return get(Instruction::FNeg, C); -} - Constant *ConstantExpr::getNot(Constant *C) { assert(C->getType()->isIntOrIntVectorTy() && "Cannot NOT a nonintegral value!"); @@ -3470,9 +3431,6 @@ return CmpInst::Create((Instruction::OtherOps)getOpcode(), (CmpInst::Predicate)getPredicate(), Ops[0], Ops[1], "", InsertBefore); - case Instruction::FNeg: - return UnaryOperator::Create((Instruction::UnaryOps)getOpcode(), Ops[0], "", - InsertBefore); default: assert(getNumOperands() == 2 && "Must be binary operator?"); BinaryOperator *BO = BinaryOperator::Create( diff --git a/llvm/lib/IR/ConstantsContext.h b/llvm/lib/IR/ConstantsContext.h --- a/llvm/lib/IR/ConstantsContext.h +++ b/llvm/lib/IR/ConstantsContext.h @@ -41,11 +41,11 @@ namespace llvm { -/// UnaryConstantExpr - This class is private to Constants.cpp, and is used -/// behind the scenes to implement unary constant exprs. -class UnaryConstantExpr final : public ConstantExpr { +/// CastConstantExpr - This class is private to Constants.cpp, and is used +/// behind the scenes to implement cast constant exprs. +class CastConstantExpr final : public ConstantExpr { public: - UnaryConstantExpr(unsigned Opcode, Constant *C, Type *Ty) + CastConstantExpr(unsigned Opcode, Constant *C, Type *Ty) : ConstantExpr(Ty, Opcode, &Op<0>(), 1) { Op<0>() = C; } @@ -57,8 +57,7 @@ DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); static bool classof(const ConstantExpr *CE) { - return Instruction::isCast(CE->getOpcode()) || - Instruction::isUnaryOp(CE->getOpcode()); + return Instruction::isCast(CE->getOpcode()); } static bool classof(const Value *V) { return isa(V) && classof(cast(V)); @@ -272,9 +271,9 @@ }; template <> -struct OperandTraits - : public FixedNumOperandTraits {}; -DEFINE_TRANSPARENT_OPERAND_ACCESSORS(UnaryConstantExpr, Value) +struct OperandTraits + : public FixedNumOperandTraits {}; +DEFINE_TRANSPARENT_OPERAND_ACCESSORS(CastConstantExpr, Value) template <> struct OperandTraits @@ -518,10 +517,8 @@ ConstantExpr *create(TypeClass *Ty) const { switch (Opcode) { default: - if (Instruction::isCast(Opcode) || - (Opcode >= Instruction::UnaryOpsBegin && - Opcode < Instruction::UnaryOpsEnd)) - return new UnaryConstantExpr(Opcode, Ops[0], Ty); + if (Instruction::isCast(Opcode)) + return new CastConstantExpr(Opcode, Ops[0], Ty); if ((Opcode >= Instruction::BinaryOpsBegin && Opcode < Instruction::BinaryOpsEnd)) return new BinaryConstantExpr(Opcode, Ops[0], Ops[1], diff --git a/llvm/lib/IR/Core.cpp b/llvm/lib/IR/Core.cpp --- a/llvm/lib/IR/Core.cpp +++ b/llvm/lib/IR/Core.cpp @@ -1549,10 +1549,6 @@ } -LLVMValueRef LLVMConstFNeg(LLVMValueRef ConstantVal) { - return wrap(ConstantExpr::getFNeg(unwrap(ConstantVal))); -} - LLVMValueRef LLVMConstNot(LLVMValueRef ConstantVal) { return wrap(ConstantExpr::getNot(unwrap(ConstantVal))); } diff --git a/llvm/test/Bindings/OCaml/core.ml b/llvm/test/Bindings/OCaml/core.ml --- a/llvm/test/Bindings/OCaml/core.ml +++ b/llvm/test/Bindings/OCaml/core.ml @@ -239,7 +239,6 @@ (* CHECK: @const_neg = global i64 sub * CHECK: @const_nsw_neg = global i64 sub nsw * CHECK: @const_nuw_neg = global i64 sub nuw - * CHECK: @const_fneg = global double fneg * CHECK: @const_not = global i64 xor * CHECK: @const_add = global i64 add * CHECK: @const_nsw_add = global i64 add nsw @@ -265,7 +264,6 @@ ignore (define_global "const_neg" (const_neg foldbomb) m); ignore (define_global "const_nsw_neg" (const_nsw_neg foldbomb) m); ignore (define_global "const_nuw_neg" (const_nuw_neg foldbomb) m); - ignore (define_global "const_fneg" (const_fneg ffoldbomb) m); ignore (define_global "const_not" (const_not foldbomb) m); ignore (define_global "const_add" (const_add foldbomb five) m); ignore (define_global "const_nsw_add" (const_nsw_add foldbomb five) m); diff --git a/llvm/test/CodeGen/AArch64/arm64-promote-const-complex-initializers.ll b/llvm/test/CodeGen/AArch64/arm64-promote-const-complex-initializers.ll --- a/llvm/test/CodeGen/AArch64/arm64-promote-const-complex-initializers.ll +++ b/llvm/test/CodeGen/AArch64/arm64-promote-const-complex-initializers.ll @@ -45,20 +45,25 @@ ; CHECK-NEXT: Lloh3: ; CHECK-NEXT: ldr q1, [x8, lCPI1_0@PAGEOFF] ; CHECK-NEXT: mov s2, v1[1] -; CHECK-NEXT: fneg s0, s1 ; CHECK-NEXT: mov s3, v1[2] +; CHECK-NEXT: fneg s0, s1 ; CHECK-NEXT: mov s1, v1[3] ; CHECK-NEXT: fneg s2, s2 +; CHECK-NEXT: fneg s3, s3 ; CHECK-NEXT: fneg s1, s1 ; CHECK-NEXT: mov.s v0[1], v2[0] -; CHECK-NEXT: fneg s2, s3 -; CHECK-NEXT: mov.s v0[2], v2[0] +; CHECK-NEXT: mov.s v0[2], v3[0] ; CHECK-NEXT: mov.s v0[3], v1[0] ; CHECK-NEXT: ret ; - ret [1 x <4 x float>] [<4 x float> - bitcast (<1 x i128> to <4 x float>), i32 0)), - float fneg (float extractelement (<4 x float> bitcast (<1 x i128> to <4 x float>), i32 1)), - float fneg (float extractelement (<4 x float> bitcast (<1 x i128> to <4 x float>), i32 2)), - float fneg (float extractelement (<4 x float> bitcast (<1 x i128> to <4 x float>), i32 3))>] + %constexpr = fneg float extractelement (<4 x float> bitcast (<1 x i128> to <4 x float>), i32 0) + %constexpr1 = fneg float extractelement (<4 x float> bitcast (<1 x i128> to <4 x float>), i32 1) + %constexpr2 = fneg float extractelement (<4 x float> bitcast (<1 x i128> to <4 x float>), i32 2) + %constexpr3 = fneg float extractelement (<4 x float> bitcast (<1 x i128> to <4 x float>), i32 3) + %constexpr.ins = insertelement <4 x float> poison, float %constexpr, i32 0 + %constexpr.ins4 = insertelement <4 x float> %constexpr.ins, float %constexpr1, i32 1 + %constexpr.ins5 = insertelement <4 x float> %constexpr.ins4, float %constexpr2, i32 2 + %constexpr.ins6 = insertelement <4 x float> %constexpr.ins5, float %constexpr3, i32 3 + %constexpr.ins7 = insertvalue [1 x <4 x float>] poison, <4 x float> %constexpr.ins6, 0 + ret [1 x <4 x float>] %constexpr.ins7 } diff --git a/llvm/test/Transforms/InstCombine/fma.ll b/llvm/test/Transforms/InstCombine/fma.ll --- a/llvm/test/Transforms/InstCombine/fma.ll +++ b/llvm/test/Transforms/InstCombine/fma.ll @@ -110,7 +110,8 @@ ; CHECK-NEXT: ret float [[FMA]] ; %y.fneg = fneg float %y - %fma = call float @llvm.fma.f32(float fneg (float bitcast (i32 ptrtoint (i32* @external to i32) to float)), float %y.fneg, float %z) + %external.fneg = fneg float bitcast (i32 ptrtoint (i32* @external to i32) to float) + %fma = call float @llvm.fma.f32(float %external.fneg, float %y.fneg, float %z) ret float %fma } @@ -131,7 +132,8 @@ ; CHECK-NEXT: ret float [[FMA]] ; %x.fneg = fneg float %x - %fma = call float @llvm.fma.f32(float %x.fneg, float fneg (float bitcast (i32 ptrtoint (i32* @external to i32) to float)), float %z) + %external.fneg = fneg float bitcast (i32 ptrtoint (i32* @external to i32) to float) + %fma = call float @llvm.fma.f32(float %x.fneg, float %external.fneg, float %z) ret float %fma } @@ -231,7 +233,8 @@ ; CHECK-NEXT: ret float [[FMULADD]] ; %y.fneg = fneg float %y - %fmuladd = call float @llvm.fmuladd.f32(float fneg (float bitcast (i32 ptrtoint (i32* @external to i32) to float)), float %y.fneg, float %z) + %external.fneg = fneg float bitcast (i32 ptrtoint (i32* @external to i32) to float) + %fmuladd = call float @llvm.fmuladd.f32(float %external.fneg, float %y.fneg, float %z) ret float %fmuladd } @@ -252,7 +255,8 @@ ; CHECK-NEXT: ret float [[FMULADD]] ; %x.fneg = fneg float %x - %fmuladd = call float @llvm.fmuladd.f32(float %x.fneg, float fneg (float bitcast (i32 ptrtoint (i32* @external to i32) to float)), float %z) + %external.fneg = fneg float bitcast (i32 ptrtoint (i32* @external to i32) to float) + %fmuladd = call float @llvm.fmuladd.f32(float %x.fneg, float %external.fneg, float %z) ret float %fmuladd } diff --git a/llvm/unittests/IR/ConstantsTest.cpp b/llvm/unittests/IR/ConstantsTest.cpp --- a/llvm/unittests/IR/ConstantsTest.cpp +++ b/llvm/unittests/IR/ConstantsTest.cpp @@ -241,7 +241,6 @@ #define P6STR "bitcast (i32 ptrtoint (ptr @dummy2 to i32) to <2 x i16>)" CHECK(ConstantExpr::getNeg(P0), "sub i32 0, " P0STR); - CHECK(ConstantExpr::getFNeg(P1), "fneg float " P1STR); CHECK(ConstantExpr::getNot(P0), "xor i32 " P0STR ", -1"); CHECK(ConstantExpr::getAdd(P0, P0), "add i32 " P0STR ", " P0STR); CHECK(ConstantExpr::getAdd(P0, P0, false, true),