Index: clang/lib/CodeGen/ItaniumCXXABI.cpp =================================================================== --- clang/lib/CodeGen/ItaniumCXXABI.cpp +++ clang/lib/CodeGen/ItaniumCXXABI.cpp @@ -955,7 +955,7 @@ adj = llvm::ConstantInt::get(adj->getType(), offset); } - llvm::Constant *srcAdj = llvm::ConstantExpr::getExtractValue(src, 1); + llvm::Constant *srcAdj = src->getAggregateElement(1); llvm::Constant *dstAdj; if (isDerivedToBase) dstAdj = llvm::ConstantExpr::getNSWSub(srcAdj, adj); Index: llvm/bindings/go/llvm/ir.go =================================================================== --- llvm/bindings/go/llvm/ir.go +++ llvm/bindings/go/llvm/ir.go @@ -993,20 +993,6 @@ return } -//TODO -//LLVMValueRef LLVMConstExtractValue(LLVMValueRef AggConstant, unsigned *IdxList, -// unsigned NumIdx); - -func ConstExtractValue(agg Value, indices []uint32) (rv Value) { - n := len(indices) - if n == 0 { - panic("one or more indices are required") - } - ptr := (*C.unsigned)(&indices[0]) - rv.C = C.LLVMConstExtractValue(agg.C, ptr, C.unsigned(n)) - return -} - func ConstInsertValue(agg, val Value, indices []uint32) (rv Value) { n := len(indices) if n == 0 { Index: llvm/bindings/ocaml/llvm/llvm.ml =================================================================== --- llvm/bindings/ocaml/llvm/llvm.ml +++ llvm/bindings/ocaml/llvm/llvm.ml @@ -702,8 +702,6 @@ = "LLVMConstInsertElement" external const_shufflevector : llvalue -> llvalue -> llvalue -> llvalue = "LLVMConstShuffleVector" -external const_extractvalue : llvalue -> int array -> llvalue - = "llvm_const_extractvalue" external const_insertvalue : llvalue -> llvalue -> int array -> llvalue = "llvm_const_insertvalue" external const_inline_asm : lltype -> string -> string -> bool -> bool -> Index: llvm/bindings/ocaml/llvm/llvm.mli =================================================================== --- llvm/bindings/ocaml/llvm/llvm.mli +++ llvm/bindings/ocaml/llvm/llvm.mli @@ -1341,11 +1341,6 @@ See the method [llvm::ConstantExpr::getShuffleVector]. *) val const_shufflevector : llvalue -> llvalue -> llvalue -> llvalue -(** [const_extractvalue agg idxs] returns the constant [idxs]th value of - constant aggregate [agg]. Each [idxs] must be less than the size of the - aggregate. See the method [llvm::ConstantExpr::getExtractValue]. *) -val const_extractvalue : llvalue -> int array -> llvalue - (** [const_insertvalue agg val idxs] inserts the value [val] in the specified indexs [idxs] in the aggregate [agg]. Each [idxs] must be less than the size of the aggregate. See the method [llvm::ConstantExpr::getInsertValue]. *) Index: llvm/bindings/ocaml/llvm/llvm_ocaml.c =================================================================== --- llvm/bindings/ocaml/llvm/llvm_ocaml.c +++ llvm/bindings/ocaml/llvm/llvm_ocaml.c @@ -1006,22 +1006,6 @@ return LLVMConstIntCast(CV, T, Bool_val(IsSigned)); } -/* llvalue -> int array -> llvalue */ -LLVMValueRef llvm_const_extractvalue(LLVMValueRef Aggregate, value Indices) { - int size = Wosize_val(Indices); - int i; - LLVMValueRef result; - - unsigned *idxs = (unsigned *)malloc(size * sizeof(unsigned)); - for (i = 0; i < size; i++) { - idxs[i] = Int_val(Field(Indices, i)); - } - - result = LLVMConstExtractValue(Aggregate, idxs, size); - free(idxs); - return result; -} - /* llvalue -> llvalue -> int array -> llvalue */ LLVMValueRef llvm_const_insertvalue(LLVMValueRef Aggregate, LLVMValueRef Val, value Indices) { Index: llvm/include/llvm-c/Core.h =================================================================== --- llvm/include/llvm-c/Core.h +++ llvm/include/llvm-c/Core.h @@ -2226,8 +2226,6 @@ LLVMValueRef LLVMConstShuffleVector(LLVMValueRef VectorAConstant, LLVMValueRef VectorBConstant, LLVMValueRef MaskConstant); -LLVMValueRef LLVMConstExtractValue(LLVMValueRef AggConstant, unsigned *IdxList, - unsigned NumIdx); LLVMValueRef LLVMConstInsertValue(LLVMValueRef AggConstant, LLVMValueRef ElementValueConstant, unsigned *IdxList, unsigned NumIdx); Index: llvm/include/llvm/Analysis/TargetFolder.h =================================================================== --- llvm/include/llvm/Analysis/TargetFolder.h +++ llvm/include/llvm/Analysis/TargetFolder.h @@ -109,7 +109,7 @@ Value *FoldExtractValue(Value *Agg, ArrayRef IdxList) const override { if (auto *CAgg = dyn_cast(Agg)) - return Fold(ConstantExpr::getExtractValue(CAgg, IdxList)); + return ConstantFoldExtractValueInstruction(CAgg, IdxList); return nullptr; }; Index: llvm/include/llvm/IR/ConstantFolder.h =================================================================== --- llvm/include/llvm/IR/ConstantFolder.h +++ llvm/include/llvm/IR/ConstantFolder.h @@ -24,6 +24,10 @@ namespace llvm { +// HACK: Expose ConstantFold.h instead. +Constant *ConstantFoldExtractValueInstruction(Constant *Agg, + ArrayRef Idxs); + /// ConstantFolder - Create constants with minimum, target independent, folding. class ConstantFolder final : public IRBuilderFolder { virtual void anchor(); @@ -97,7 +101,7 @@ Value *FoldExtractValue(Value *Agg, ArrayRef IdxList) const override { if (auto *CAgg = dyn_cast(Agg)) - return ConstantExpr::getExtractValue(CAgg, IdxList); + return ConstantFoldExtractValueInstruction(CAgg, IdxList); return nullptr; }; Index: llvm/include/llvm/IR/Constants.h =================================================================== --- llvm/include/llvm/IR/Constants.h +++ llvm/include/llvm/IR/Constants.h @@ -1290,8 +1290,6 @@ static Constant *getShuffleVector(Constant *V1, Constant *V2, ArrayRef Mask, Type *OnlyIfReducedTy = nullptr); - static Constant *getExtractValue(Constant *Agg, ArrayRef Idxs, - Type *OnlyIfReducedTy = nullptr); static Constant *getInsertValue(Constant *Agg, Constant *Val, ArrayRef Idxs, Type *OnlyIfReducedTy = nullptr); Index: llvm/lib/Analysis/ConstantFolding.cpp =================================================================== --- llvm/lib/Analysis/ConstantFolding.cpp +++ llvm/lib/Analysis/ConstantFolding.cpp @@ -1035,7 +1035,7 @@ case Instruction::ExtractElement: return ConstantExpr::getExtractElement(Ops[0], Ops[1]); case Instruction::ExtractValue: - return ConstantExpr::getExtractValue( + return ConstantFoldExtractValueInstruction( Ops[0], cast(InstOrCE)->getIndices()); case Instruction::InsertElement: return ConstantExpr::getInsertElement(Ops[0], Ops[1], Ops[2]); @@ -1151,7 +1151,7 @@ return ConstantExpr::getInsertValue(Ops[0], Ops[1], IVI->getIndices()); if (auto *EVI = dyn_cast(I)) - return ConstantExpr::getExtractValue(Ops[0], EVI->getIndices()); + return ConstantFoldExtractValueInstruction(Ops[0], EVI->getIndices()); return ConstantFoldInstOperands(I, Ops, DL, TLI); } Index: llvm/lib/Analysis/InlineCost.cpp =================================================================== --- llvm/lib/Analysis/InlineCost.cpp +++ llvm/lib/Analysis/InlineCost.cpp @@ -2072,7 +2072,7 @@ bool CallAnalyzer::visitExtractValue(ExtractValueInst &I) { // Constant folding for extract value is trivial. if (simplifyInstruction(I, [&](SmallVectorImpl &COps) { - return ConstantExpr::getExtractValue(COps[0], I.getIndices()); + return ConstantFoldExtractValueInstruction(COps[0], I.getIndices()); })) return true; Index: llvm/lib/AsmParser/LLParser.cpp =================================================================== --- llvm/lib/AsmParser/LLParser.cpp +++ llvm/lib/AsmParser/LLParser.cpp @@ -3387,24 +3387,8 @@ ID.Kind = ValID::t_Constant; return false; } - case lltok::kw_extractvalue: { - Lex.Lex(); - Constant *Val; - SmallVector Indices; - if (parseToken(lltok::lparen, - "expected '(' in extractvalue constantexpr") || - parseGlobalTypeAndValue(Val) || parseIndexList(Indices) || - parseToken(lltok::rparen, "expected ')' in extractvalue constantexpr")) - return true; - - if (!Val->getType()->isAggregateType()) - return error(ID.Loc, "extractvalue operand must be aggregate type"); - if (!ExtractValueInst::getIndexedType(Val->getType(), Indices)) - return error(ID.Loc, "invalid indices for extractvalue"); - ID.ConstantVal = ConstantExpr::getExtractValue(Val, Indices); - ID.Kind = ValID::t_Constant; - return false; - } + case lltok::kw_extractvalue: + return error(ID.Loc, "extractvalue constexprs are no longer supported"); case lltok::kw_insertvalue: { Lex.Lex(); Constant *Val0, *Val1; Index: llvm/lib/IR/Constants.cpp =================================================================== --- llvm/lib/IR/Constants.cpp +++ llvm/lib/IR/Constants.cpp @@ -1541,8 +1541,6 @@ case Instruction::InsertValue: return ConstantExpr::getInsertValue(Ops[0], Ops[1], getIndices(), OnlyIfReducedTy); - case Instruction::ExtractValue: - return ConstantExpr::getExtractValue(Ops[0], getIndices(), OnlyIfReducedTy); case Instruction::FNeg: return ConstantExpr::getFNeg(Ops[0]); case Instruction::ShuffleVector: @@ -2669,30 +2667,6 @@ return pImpl->ExprConstants.getOrCreate(ReqTy, Key); } -Constant *ConstantExpr::getExtractValue(Constant *Agg, ArrayRef Idxs, - Type *OnlyIfReducedTy) { - assert(Agg->getType()->isFirstClassType() && - "Tried to create extractelement operation on non-first-class type!"); - - Type *ReqTy = ExtractValueInst::getIndexedType(Agg->getType(), Idxs); - (void)ReqTy; - assert(ReqTy && "extractvalue indices invalid!"); - - assert(Agg->getType()->isFirstClassType() && - "Non-first-class type for constant extractvalue expression"); - if (Constant *FC = ConstantFoldExtractValueInstruction(Agg, Idxs)) - return FC; - - if (OnlyIfReducedTy == ReqTy) - return nullptr; - - Constant *ArgVec[] = { Agg }; - const ConstantExprKeyType Key(Instruction::ExtractValue, ArgVec, 0, 0, Idxs); - - LLVMContextImpl *pImpl = Agg->getContext().pImpl; - return pImpl->ExprConstants.getOrCreate(ReqTy, Key); -} - Constant *ConstantExpr::getNeg(Constant *C, bool HasNUW, bool HasNSW) { assert(C->getType()->isIntOrIntVectorTy() && "Cannot NEG a nonintegral value!"); Index: llvm/lib/IR/Core.cpp =================================================================== --- llvm/lib/IR/Core.cpp +++ llvm/lib/IR/Core.cpp @@ -1871,12 +1871,6 @@ IntMask)); } -LLVMValueRef LLVMConstExtractValue(LLVMValueRef AggConstant, unsigned *IdxList, - unsigned NumIdx) { - return wrap(ConstantExpr::getExtractValue(unwrap(AggConstant), - makeArrayRef(IdxList, NumIdx))); -} - LLVMValueRef LLVMConstInsertValue(LLVMValueRef AggConstant, LLVMValueRef ElementValueConstant, unsigned *IdxList, unsigned NumIdx) { Index: llvm/lib/Transforms/Coroutines/CoroElide.cpp =================================================================== --- llvm/lib/Transforms/Coroutines/CoroElide.cpp +++ llvm/lib/Transforms/Coroutines/CoroElide.cpp @@ -336,14 +336,13 @@ assert(Resumers && "PostSplit coro.id Info argument must refer to an array" "of coroutine subfunctions"); auto *ResumeAddrConstant = - ConstantExpr::getExtractValue(Resumers, CoroSubFnInst::ResumeIndex); + Resumers->getAggregateElement(CoroSubFnInst::ResumeIndex); replaceWithConstant(ResumeAddrConstant, ResumeAddr); bool ShouldElide = shouldElide(CoroId->getFunction(), DT); - auto *DestroyAddrConstant = ConstantExpr::getExtractValue( - Resumers, + auto *DestroyAddrConstant = Resumers->getAggregateElement( ShouldElide ? CoroSubFnInst::CleanupIndex : CoroSubFnInst::DestroyIndex); for (auto &It : DestroyAddr) Index: llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp =================================================================== --- llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp +++ llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp @@ -190,8 +190,11 @@ if (!Elt) return nullptr; // If this is indexing an array of structures, get the structure element. - if (!LaterIndices.empty()) - Elt = ConstantExpr::getExtractValue(Elt, LaterIndices); + if (!LaterIndices.empty()) { + Elt = ConstantFoldExtractValueInstruction(Elt, LaterIndices); + if (!Elt) + return nullptr; + } // If the element is masked, handle it. if (AndCst) Elt = ConstantExpr::getAnd(Elt, AndCst); Index: llvm/lib/Transforms/Utils/Evaluator.cpp =================================================================== --- llvm/lib/Transforms/Utils/Evaluator.cpp +++ llvm/lib/Transforms/Utils/Evaluator.cpp @@ -358,8 +358,10 @@ LLVM_DEBUG(dbgs() << "Found a Select! Simplifying: " << *InstResult << "\n"); } else if (auto *EVI = dyn_cast(CurInst)) { - InstResult = ConstantExpr::getExtractValue( + InstResult = ConstantFoldExtractValueInstruction( getVal(EVI->getAggregateOperand()), EVI->getIndices()); + if (!InstResult) + return false; LLVM_DEBUG(dbgs() << "Found an ExtractValueInst! Simplifying: " << *InstResult << "\n"); } else if (auto *IVI = dyn_cast(CurInst)) { Index: llvm/test/Assembler/insertextractvalue.ll =================================================================== --- llvm/test/Assembler/insertextractvalue.ll +++ llvm/test/Assembler/insertextractvalue.ll @@ -15,28 +15,25 @@ ret float %s } -; CHECK: @bar +; CHECK-LABEL: @bar ; CHECK-NEXT: store { { i32 }, { float, double } } { { i32 } { i32 4 }, { float, double } { float 4.000000e+00, double 2.000000e+01 } }, { { i32 }, { float, double } }* %p -; CHECK-NEXT: ret float 7.000000e+00 -define float @bar({{i32},{float, double}}* %p) nounwind { +define void @bar({{i32},{float, double}}* %p) nounwind { store {{i32},{float, double}} insertvalue ({{i32},{float, double}}{{i32}{i32 4},{float, double}{float 4.0, double 5.0}}, double 20.0, 1, 1), {{i32},{float, double}}* %p - ret float extractvalue ({{i32},{float, double}}{{i32}{i32 3},{float, double}{float 7.0, double 9.0}}, 1, 0) + ret void } -; CHECK: @car +; CHECK-LABEL: @car ; CHECK-NEXT: store { { i32 }, { float, double } } { { i32 } undef, { float, double } { float undef, double 2.000000e+01 } }, { { i32 }, { float, double } }* %p -; CHECK-NEXT: ret float undef -define float @car({{i32},{float, double}}* %p) nounwind { +define void @car({{i32},{float, double}}* %p) nounwind { store {{i32},{float, double}} insertvalue ({{i32},{float, double}} undef, double 20.0, 1, 1), {{i32},{float, double}}* %p - ret float extractvalue ({{i32},{float, double}} undef, 1, 0) + ret void } -; CHECK: @dar +; CHECK-LABEL: @dar ; CHECK-NEXT: store { { i32 }, { float, double } } { { i32 } zeroinitializer, { float, double } { float 0.000000e+00, double 2.000000e+01 } }, { { i32 }, { float, double } }* %p -; CHECK-NEXT: ret float 0.000000e+00 -define float @dar({{i32},{float, double}}* %p) nounwind { +define void @dar({{i32},{float, double}}* %p) nounwind { store {{i32},{float, double}} insertvalue ({{i32},{float, double}} zeroinitializer, double 20.0, 1, 1), {{i32},{float, double}}* %p - ret float extractvalue ({{i32},{float, double}} zeroinitializer, 1, 0) + ret void } ; PR4963 Index: llvm/test/Assembler/unsupported-constexprs.ll =================================================================== --- /dev/null +++ llvm/test/Assembler/unsupported-constexprs.ll @@ -0,0 +1,6 @@ +; RUN: not llvm-as < %s 2>&1 | FileCheck %s + +define float @extractvalue() { +; CHECK: [[@LINE+1]]:13: error: extractvalue constexprs are no longer supported + ret float extractvalue ({i32} {i32 3}, 0) +} Index: llvm/test/CodeGen/Generic/pr33094.ll =================================================================== --- llvm/test/CodeGen/Generic/pr33094.ll +++ llvm/test/CodeGen/Generic/pr33094.ll @@ -12,7 +12,8 @@ @B_Inst = global %B zeroinitializer define i64 @foo() { - ret i64 extractvalue (%Tuple select (i1 icmp eq + %e = extractvalue %Tuple select (i1 icmp eq (%B* bitcast (%A* @A_Inst to %B*), %B* @B_Inst), - %Tuple { i64 33 }, %Tuple { i64 42 }), 0) + %Tuple { i64 33 }, %Tuple { i64 42 }), 0 + ret i64 %e } Index: llvm/test/CodeGen/X86/nonconst-static-ev.ll =================================================================== --- llvm/test/CodeGen/X86/nonconst-static-ev.ll +++ /dev/null @@ -1,8 +0,0 @@ -; RUN: not --crash llc -mtriple=i686-linux-gnu < %s 2> %t -; RUN: FileCheck --check-prefix=CHECK-ERRORS < %t %s - -@0 = global i8 extractvalue ([1 x i8] select (i1 ptrtoint (i32* @1 to i1), [1 x i8] [ i8 1 ], [1 x i8] [ i8 2 ]), 0) -@1 = external global i32 - -; CHECK-ERRORS: Unsupported expression in static initializer: extractvalue - Index: llvm/test/Transforms/InstCombine/cast.ll =================================================================== --- llvm/test/Transforms/InstCombine/cast.ll +++ llvm/test/Transforms/InstCombine/cast.ll @@ -1470,7 +1470,8 @@ ; LE-LABEL: @PR28745( ; LE-NEXT: ret i64 0 ; - %b = zext i32 extractvalue ({ i32 } select (i1 icmp eq (i16 extractelement (<2 x i16> bitcast (<1 x i32> to <2 x i16>), i32 0), i16 0), { i32 } { i32 1 }, { i32 } zeroinitializer), 0) to i64 + %e = extractvalue { i32 } select (i1 icmp eq (i16 extractelement (<2 x i16> bitcast (<1 x i32> to <2 x i16>), i32 0), i16 0), { i32 } { i32 1 }, { i32 } zeroinitializer), 0 + %b = zext i32 %e to i64 ret i64 %b } Index: llvm/test/Transforms/InstCombine/pr28725.ll =================================================================== --- llvm/test/Transforms/InstCombine/pr28725.ll +++ llvm/test/Transforms/InstCombine/pr28725.ll @@ -3,7 +3,8 @@ define <2 x i16> @test1() { entry: - %b = insertelement <2 x i16> , i16 extractvalue (%S select (i1 icmp eq (i16 extractelement (<2 x i16> bitcast (<1 x i32> to <2 x i16>), i32 0), i16 0), %S zeroinitializer, %S { i16 0, i32 1 }), 0), i32 0 + %e = extractvalue %S select (i1 icmp eq (i16 extractelement (<2 x i16> bitcast (<1 x i32> to <2 x i16>), i32 0), i16 0), %S zeroinitializer, %S { i16 0, i32 1 }), 0 + %b = insertelement <2 x i16> , i16 %e, i32 0 ret <2 x i16> %b } Index: llvm/test/Transforms/InstSimplify/pr28725.ll =================================================================== --- llvm/test/Transforms/InstSimplify/pr28725.ll +++ llvm/test/Transforms/InstSimplify/pr28725.ll @@ -1,12 +1,17 @@ +; NOTE: Assertions have been autogenerated by utils/update_test_checks.py ; RUN: opt -S -passes=instsimplify < %s | FileCheck %s %S = type { i16, i32 } +; InstCombine will be able to fold this into zeroinitializer define <2 x i16> @test1() { +; CHECK-LABEL: @test1( +; CHECK-NEXT: entry: +; CHECK-NEXT: [[E:%.*]] = extractvalue [[S:%.*]] select (i1 icmp eq (i16 extractelement (<2 x i16> bitcast (<1 x i32> to <2 x i16>), i32 0), i16 0), [[S]] zeroinitializer, [[S]] { i16 0, i32 1 }), 0 +; CHECK-NEXT: [[B:%.*]] = insertelement <2 x i16> , i16 [[E]], i32 0 +; CHECK-NEXT: ret <2 x i16> [[B]] +; entry: - %b = insertelement <2 x i16> , i16 extractvalue (%S select (i1 icmp eq (i16 extractelement (<2 x i16> bitcast (<1 x i32> to <2 x i16>), i32 0), i16 0), %S zeroinitializer, %S { i16 0, i32 1 }), 0), i32 0 + %e = extractvalue %S select (i1 icmp eq (i16 extractelement (<2 x i16> bitcast (<1 x i32> to <2 x i16>), i32 0), i16 0), %S zeroinitializer, %S { i16 0, i32 1 }), 0 + %b = insertelement <2 x i16> , i16 %e, i32 0 ret <2 x i16> %b } - -; InstCombine will be able to fold this into zeroinitializer -; CHECK-LABEL: @test1( -; CHECK: ret <2 x i16> bitcast (<1 x i32> to <2 x i16>), i32 0), i16 0), %S zeroinitializer, %S { i16 0, i32 1 }), 0), i16 0>