diff --git a/llvm/bindings/ocaml/llvm/llvm.ml b/llvm/bindings/ocaml/llvm/llvm.ml index 581d832430074..057798fc0cea2 100644 --- a/llvm/bindings/ocaml/llvm/llvm.ml +++ b/llvm/bindings/ocaml/llvm/llvm.ml @@ -654,8 +654,6 @@ external const_icmp : Icmp.t -> llvalue -> llvalue -> llvalue external const_fcmp : Fcmp.t -> llvalue -> llvalue -> llvalue = "llvm_const_fcmp" external const_shl : llvalue -> llvalue -> llvalue = "llvm_const_shl" -external const_lshr : llvalue -> llvalue -> llvalue = "llvm_const_lshr" -external const_ashr : llvalue -> llvalue -> llvalue = "llvm_const_ashr" external const_gep : lltype -> llvalue -> llvalue array -> llvalue = "llvm_const_gep" external const_in_bounds_gep : lltype -> llvalue -> llvalue array -> llvalue diff --git a/llvm/bindings/ocaml/llvm/llvm.mli b/llvm/bindings/ocaml/llvm/llvm.mli index f9aab89e4bddf..e0febb79a2b61 100644 --- a/llvm/bindings/ocaml/llvm/llvm.mli +++ b/llvm/bindings/ocaml/llvm/llvm.mli @@ -1145,16 +1145,6 @@ val const_fcmp : Fcmp.t -> llvalue -> llvalue -> llvalue See the method [llvm::ConstantExpr::getShl]. *) val const_shl : llvalue -> llvalue -> llvalue -(** [const_lshr c1 c2] returns the constant integer [c1] right-shifted by the - constant integer [c2] with zero extension. - See the method [llvm::ConstantExpr::getLShr]. *) -val const_lshr : llvalue -> llvalue -> llvalue - -(** [const_ashr c1 c2] returns the constant integer [c1] right-shifted by the - constant integer [c2] with sign extension. - See the method [llvm::ConstantExpr::getAShr]. *) -val const_ashr : llvalue -> llvalue -> llvalue - (** [const_gep srcty pc indices] returns the constant [getElementPtr] of [pc] with source element type [srcty] and the constant integers indices from the array [indices]. diff --git a/llvm/bindings/ocaml/llvm/llvm_ocaml.c b/llvm/bindings/ocaml/llvm/llvm_ocaml.c index 4c4c49027206c..d74d8030cea0d 100644 --- a/llvm/bindings/ocaml/llvm/llvm_ocaml.c +++ b/llvm/bindings/ocaml/llvm/llvm_ocaml.c @@ -1233,18 +1233,6 @@ value llvm_const_shl(value LHS, value RHS) { return to_val(Value); } -/* llvalue -> llvalue -> llvalue */ -value llvm_const_lshr(value LHS, value RHS) { - LLVMValueRef Value = LLVMConstLShr(Value_val(LHS), Value_val(RHS)); - return to_val(Value); -} - -/* llvalue -> llvalue -> llvalue */ -value llvm_const_ashr(value LHS, value RHS) { - LLVMValueRef Value = LLVMConstAShr(Value_val(LHS), Value_val(RHS)); - return to_val(Value); -} - /* lltype -> llvalue -> llvalue array -> llvalue */ value llvm_const_gep(value Ty, value ConstantVal, value Indices) { mlsize_t Length = Wosize_val(Indices); diff --git a/llvm/docs/LangRef.rst b/llvm/docs/LangRef.rst index ff4f769dcc0db..bc1eab1e0b7a0 100644 --- a/llvm/docs/LangRef.rst +++ b/llvm/docs/LangRef.rst @@ -4693,10 +4693,6 @@ The following is the syntax for constant expressions: Perform a multiplication on constants. ``shl (LHS, RHS)`` Perform a left shift on constants. -``lshr (LHS, RHS)`` - Perform a logical right shift on constants. -``ashr (LHS, RHS)`` - Perform an arithmetic right shift on constants. ``xor (LHS, RHS)`` Perform a bitwise xor on constants. diff --git a/llvm/docs/ReleaseNotes.rst b/llvm/docs/ReleaseNotes.rst index d39bd75a9bd47..e27a81316c2ce 100644 --- a/llvm/docs/ReleaseNotes.rst +++ b/llvm/docs/ReleaseNotes.rst @@ -57,6 +57,8 @@ Changes to the LLVM IR * ``and`` * ``or`` + * ``lshr`` + * ``ashr`` * ``zext`` * ``sext`` * ``fptrunc`` @@ -174,6 +176,8 @@ Changes to the C API * ``LLVMConstAnd`` * ``LLVMConstOr`` + * ``LLVMConstLShr`` + * ``LLVMConstAShr`` * ``LLVMConstZExt`` * ``LLVMConstSExt`` * ``LLVMConstZExtOrBitCast`` diff --git a/llvm/include/llvm-c/Core.h b/llvm/include/llvm-c/Core.h index 41e148e89fbd2..b752fd42a7a12 100644 --- a/llvm/include/llvm-c/Core.h +++ b/llvm/include/llvm-c/Core.h @@ -2281,8 +2281,6 @@ LLVMValueRef LLVMConstICmp(LLVMIntPredicate Predicate, LLVMValueRef LLVMConstFCmp(LLVMRealPredicate Predicate, LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); LLVMValueRef LLVMConstShl(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); -LLVMValueRef LLVMConstLShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); -LLVMValueRef LLVMConstAShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant); LLVMValueRef LLVMConstGEP2(LLVMTypeRef Ty, LLVMValueRef ConstantVal, LLVMValueRef *ConstantIndices, unsigned NumIndices); LLVMValueRef LLVMConstInBoundsGEP2(LLVMTypeRef Ty, LLVMValueRef ConstantVal, diff --git a/llvm/include/llvm/IR/Constants.h b/llvm/include/llvm/IR/Constants.h index cf3812a79f028..c443ec58822b0 100644 --- a/llvm/include/llvm/IR/Constants.h +++ b/llvm/include/llvm/IR/Constants.h @@ -1038,8 +1038,6 @@ class ConstantExpr : public Constant { static Constant *getXor(Constant *C1, Constant *C2); static Constant *getShl(Constant *C1, Constant *C2, bool HasNUW = false, bool HasNSW = false); - static Constant *getLShr(Constant *C1, Constant *C2, bool isExact = false); - static Constant *getAShr(Constant *C1, Constant *C2, bool isExact = false); static Constant *getTrunc(Constant *C, Type *Ty, bool OnlyIfReduced = false); static Constant *getPtrToInt(Constant *C, Type *Ty, bool OnlyIfReduced = false); @@ -1085,14 +1083,6 @@ class ConstantExpr : public Constant { return getShl(C1, C2, true, false); } - static Constant *getExactAShr(Constant *C1, Constant *C2) { - return getAShr(C1, C2, true); - } - - static Constant *getExactLShr(Constant *C1, Constant *C2) { - return getLShr(C1, C2, true); - } - /// If C is a scalar/fixed width vector of known powers of 2, then this /// function returns a new scalar/fixed width vector obtained from logBase2 /// of C. Undef vector elements are set to zero. diff --git a/llvm/lib/AsmParser/LLParser.cpp b/llvm/lib/AsmParser/LLParser.cpp index 9940bfb15d197..f9df70fb6fc09 100644 --- a/llvm/lib/AsmParser/LLParser.cpp +++ b/llvm/lib/AsmParser/LLParser.cpp @@ -3852,6 +3852,10 @@ bool LLParser::parseValID(ValID &ID, PerFunctionState *PFS, Type *ExpectedTy) { return error(ID.Loc, "and constexprs are no longer supported"); case lltok::kw_or: return error(ID.Loc, "or constexprs are no longer supported"); + case lltok::kw_lshr: + return error(ID.Loc, "lshr constexprs are no longer supported"); + case lltok::kw_ashr: + return error(ID.Loc, "ashr constexprs are no longer supported"); case lltok::kw_fneg: return error(ID.Loc, "fneg constexprs are no longer supported"); case lltok::kw_select: @@ -3910,12 +3914,9 @@ bool LLParser::parseValID(ValID &ID, PerFunctionState *PFS, Type *ExpectedTy) { case lltok::kw_sub: case lltok::kw_mul: case lltok::kw_shl: - case lltok::kw_lshr: - case lltok::kw_ashr: case lltok::kw_xor: { bool NUW = false; bool NSW = false; - bool Exact = false; unsigned Opc = Lex.getUIntVal(); Constant *Val0, *Val1; Lex.Lex(); @@ -3928,10 +3929,6 @@ bool LLParser::parseValID(ValID &ID, PerFunctionState *PFS, Type *ExpectedTy) { if (EatIfPresent(lltok::kw_nuw)) NUW = true; } - } else if (Opc == Instruction::SDiv || Opc == Instruction::UDiv || - Opc == Instruction::LShr || Opc == Instruction::AShr) { - if (EatIfPresent(lltok::kw_exact)) - Exact = true; } if (parseToken(lltok::lparen, "expected '(' in binary constantexpr") || parseGlobalTypeAndValue(Val0) || @@ -3948,7 +3945,6 @@ bool LLParser::parseValID(ValID &ID, PerFunctionState *PFS, Type *ExpectedTy) { unsigned Flags = 0; if (NUW) Flags |= OverflowingBinaryOperator::NoUnsignedWrap; if (NSW) Flags |= OverflowingBinaryOperator::NoSignedWrap; - if (Exact) Flags |= PossiblyExactOperator::IsExact; ID.ConstantVal = ConstantExpr::get(Opc, Val0, Val1, Flags); ID.Kind = ValID::t_Constant; return false; diff --git a/llvm/lib/IR/ConstantFold.cpp b/llvm/lib/IR/ConstantFold.cpp index 0358f996f2851..25f7ac22e3ab6 100644 --- a/llvm/lib/IR/ConstantFold.cpp +++ b/llvm/lib/IR/ConstantFold.cpp @@ -155,29 +155,6 @@ static Constant *ExtractConstantBytes(Constant *C, unsigned ByteStart, switch (CE->getOpcode()) { default: return nullptr; - case Instruction::LShr: { - ConstantInt *Amt = dyn_cast(CE->getOperand(1)); - if (!Amt) - return nullptr; - APInt ShAmt = Amt->getValue(); - // Cannot analyze non-byte shifts. - if ((ShAmt & 7) != 0) - return nullptr; - ShAmt.lshrInPlace(3); - - // If the extract is known to be all zeros, return zero. - if (ShAmt.uge(CSize - ByteStart)) - return Constant::getNullValue( - IntegerType::get(CE->getContext(), ByteSize * 8)); - // If the extract is known to be fully in the input, extract it. - if (ShAmt.ule(CSize - (ByteStart + ByteSize))) - return ExtractConstantBytes(CE->getOperand(0), - ByteStart + ShAmt.getZExtValue(), ByteSize); - - // TODO: Handle the 'partially zero' case. - return nullptr; - } - case Instruction::Shl: { ConstantInt *Amt = dyn_cast(CE->getOperand(1)); if (!Amt) diff --git a/llvm/lib/IR/Constants.cpp b/llvm/lib/IR/Constants.cpp index aab624bf8dec5..bc55d5b485271 100644 --- a/llvm/lib/IR/Constants.cpp +++ b/llvm/lib/IR/Constants.cpp @@ -2160,13 +2160,13 @@ bool ConstantExpr::isSupportedBinOp(unsigned Opcode) { case Instruction::FRem: case Instruction::And: case Instruction::Or: + case Instruction::LShr: + case Instruction::AShr: return false; case Instruction::Add: case Instruction::Sub: case Instruction::Mul: case Instruction::Shl: - case Instruction::LShr: - case Instruction::AShr: case Instruction::Xor: return true; default: @@ -2482,16 +2482,6 @@ Constant *ConstantExpr::getShl(Constant *C1, Constant *C2, return get(Instruction::Shl, C1, C2, Flags); } -Constant *ConstantExpr::getLShr(Constant *C1, Constant *C2, bool isExact) { - return get(Instruction::LShr, C1, C2, - isExact ? PossiblyExactOperator::IsExact : 0); -} - -Constant *ConstantExpr::getAShr(Constant *C1, Constant *C2, bool isExact) { - return get(Instruction::AShr, C1, C2, - isExact ? PossiblyExactOperator::IsExact : 0); -} - Constant *ConstantExpr::getExactLogBase2(Constant *C) { Type *Ty = C->getType(); const APInt *IVal; diff --git a/llvm/lib/IR/Core.cpp b/llvm/lib/IR/Core.cpp index 004b0e8577a7e..f838b0501a889 100644 --- a/llvm/lib/IR/Core.cpp +++ b/llvm/lib/IR/Core.cpp @@ -1712,16 +1712,6 @@ LLVMValueRef LLVMConstShl(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) { unwrap(RHSConstant))); } -LLVMValueRef LLVMConstLShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) { - return wrap(ConstantExpr::getLShr(unwrap(LHSConstant), - unwrap(RHSConstant))); -} - -LLVMValueRef LLVMConstAShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) { - return wrap(ConstantExpr::getAShr(unwrap(LHSConstant), - unwrap(RHSConstant))); -} - LLVMValueRef LLVMConstGEP2(LLVMTypeRef Ty, LLVMValueRef ConstantVal, LLVMValueRef *ConstantIndices, unsigned NumIndices) { ArrayRef IdxList(unwrap(ConstantIndices, NumIndices), diff --git a/llvm/test/Assembler/2003-05-21-MalformedShiftCrash.ll b/llvm/test/Assembler/2003-05-21-MalformedShiftCrash.ll index 0ec3c8b1045cb..a0dda4553c9aa 100644 --- a/llvm/test/Assembler/2003-05-21-MalformedShiftCrash.ll +++ b/llvm/test/Assembler/2003-05-21-MalformedShiftCrash.ll @@ -2,4 +2,4 @@ ; RUN: not llvm-as < %s > /dev/null 2> %t ; RUN: grep "constexpr requires integer or integer vector operands" %t -@0 = global i32 ashr (float 1.0, float 2.0) +@0 = global i32 shl (float 1.0, float 2.0) diff --git a/llvm/test/Assembler/2003-11-05-ConstantExprShift.ll b/llvm/test/Assembler/2003-11-05-ConstantExprShift.ll deleted file mode 100644 index 6aa58232b314f..0000000000000 --- a/llvm/test/Assembler/2003-11-05-ConstantExprShift.ll +++ /dev/null @@ -1,6 +0,0 @@ -; RUN: llvm-as < %s | llvm-dis -; RUN: verify-uselistorder %s - -define i32 @test() { - ret i32 ashr (i32 ptrtoint (ptr @test to i32), i32 2) -} diff --git a/llvm/test/Assembler/flags.ll b/llvm/test/Assembler/flags.ll index 8331edf52a169..6ab5e1bfb9c4f 100644 --- a/llvm/test/Assembler/flags.ll +++ b/llvm/test/Assembler/flags.ll @@ -174,16 +174,6 @@ define i64 @mul_both_ce() { ret i64 mul nuw nsw (i64 ptrtoint (ptr @addr to i64), i64 91) } -define i64 @ashr_exact_ce() { -; CHECK: ret i64 ashr exact (i64 ptrtoint (ptr @addr to i64), i64 9) - ret i64 ashr exact (i64 ptrtoint (ptr @addr to i64), i64 9) -} - -define i64 @lshr_exact_ce() { -; CHECK: ret i64 lshr exact (i64 ptrtoint (ptr @addr to i64), i64 9) - ret i64 lshr exact (i64 ptrtoint (ptr @addr to i64), i64 9) -} - define ptr @gep_nw_ce() { ; CHECK: ret ptr getelementptr inbounds (i64, ptr @addr, i64 171) ret ptr getelementptr inbounds (i64, ptr @addr, i64 171) diff --git a/llvm/test/Assembler/vector-shift.ll b/llvm/test/Assembler/vector-shift.ll index d4351a87ce943..ba8708bac8cf0 100644 --- a/llvm/test/Assembler/vector-shift.ll +++ b/llvm/test/Assembler/vector-shift.ll @@ -24,23 +24,3 @@ entry: %cmp = ashr <4 x i32> %a, %b ; <4 x i32> [#uses=1] ret <4 x i32> %cmp } - -; Constant expressions: these should be folded. - -; CHECK: @foo_ce -; CHECK: ret <2 x i64> -define <2 x i64> @foo_ce() nounwind { - ret <2 x i64> shl (<2 x i64> , <2 x i64> ) -} - -; CHECK: @bar_ce -; CHECK: ret <2 x i64> -define <2 x i64> @bar_ce() nounwind { - ret <2 x i64> lshr (<2 x i64> , <2 x i64> ) -} - -; CHECK: baz_ce -; CHECK: ret <2 x i64> -define <2 x i64> @baz_ce() nounwind { - ret <2 x i64> ashr (<2 x i64> , <2 x i64> ) -} diff --git a/llvm/test/CodeGen/AArch64/fold-global-offsets.ll b/llvm/test/CodeGen/AArch64/fold-global-offsets.ll index 34b13faad69b7..897d35a78495b 100644 --- a/llvm/test/CodeGen/AArch64/fold-global-offsets.ll +++ b/llvm/test/CodeGen/AArch64/fold-global-offsets.ll @@ -131,6 +131,10 @@ define i32 @f7() { ; GISEL-NEXT: ret entry: - %l = load i32, ptr getelementptr (i32, ptr inttoptr (i64 trunc (i128 lshr (i128 bitcast (<2 x i64> to i128), i128 64) to i64) to ptr), i64 5) + %lshr = lshr i128 bitcast (<2 x i64> to i128), 64 + %trunc = trunc i128 %lshr to i64 + %inttoptr = inttoptr i64 %trunc to ptr + %gep = getelementptr i32, ptr %inttoptr, i64 5 + %l = load i32, ptr %gep ret i32 %l } diff --git a/llvm/test/CodeGen/X86/2009-01-18-ConstantExprCrash.ll b/llvm/test/CodeGen/X86/2009-01-18-ConstantExprCrash.ll index ad4458c0621c7..c5541d65c6c3a 100644 --- a/llvm/test/CodeGen/X86/2009-01-18-ConstantExprCrash.ll +++ b/llvm/test/CodeGen/X86/2009-01-18-ConstantExprCrash.ll @@ -25,7 +25,10 @@ bb4.i.i70: ; preds = %bb4.i.i70, %bb.i51 br i1 false, label %_ZN11xercesc_2_59XMLString9stringLenEPKt.exit.i73, label %bb4.i.i70 _ZN11xercesc_2_59XMLString9stringLenEPKt.exit.i73: ; preds = %bb4.i.i70 - %0 = load i16, ptr getelementptr ([7 x i16], ptr @_ZN11xercesc_2_5L17gIdeographicCharsE, i32 0, i32 add (i32 ashr (i32 sub (i32 ptrtoint (ptr getelementptr ([7 x i16], ptr @_ZN11xercesc_2_5L17gIdeographicCharsE, i32 0, i32 4) to i32), i32 ptrtoint (ptr @_ZN11xercesc_2_5L17gIdeographicCharsE to i32)), i32 1), i32 1)), align 4 ; [#uses=0] + %ashr = ashr i32 sub (i32 ptrtoint (ptr getelementptr ([7 x i16], ptr @_ZN11xercesc_2_5L17gIdeographicCharsE, i32 0, i32 4) to i32), i32 ptrtoint (ptr @_ZN11xercesc_2_5L17gIdeographicCharsE to i32)), 1 + %add = add i32 %ashr, 1 + %gep = getelementptr [7 x i16], ptr @_ZN11xercesc_2_5L17gIdeographicCharsE, i32 0, i32 %add + %0 = load i16, ptr %gep, align 4 br label %bb4.i5.i141 bb4.i5.i141: ; preds = %bb4.i5.i141, %_ZN11xercesc_2_59XMLString9stringLenEPKt.exit.i73 diff --git a/llvm/test/CodeGen/X86/pre-coalesce-2.ll b/llvm/test/CodeGen/X86/pre-coalesce-2.ll index 67d57408c9c2d..55e9fb6ee184b 100644 --- a/llvm/test/CodeGen/X86/pre-coalesce-2.ll +++ b/llvm/test/CodeGen/X86/pre-coalesce-2.ll @@ -86,7 +86,10 @@ if.end5: ; preds = %while.body br i1 %cmp6, label %if.end14, label %cleanup.thread40 if.end14: ; preds = %if.end5 - %22 = load i8, ptr inttoptr (i64 add (i64 lshr (i64 ptrtoint (ptr @a to i64), i64 3), i64 2147450880) to ptr) + %lshr1 = lshr i64 ptrtoint (ptr @a to i64), 3 + %add1 = add i64 %lshr1, 2147450880 + %inttoptr1 = inttoptr i64 %add1 to ptr + %22 = load i8, ptr %inttoptr1 %23 = icmp ne i8 %22, 0 br i1 %23, label %24, label %25 @@ -177,7 +180,10 @@ cleanup.thread40: ; preds = %if.end5 br label %enoent cleanup: ; preds = %while.body - %61 = load i8, ptr inttoptr (i64 add (i64 lshr (i64 ptrtoint (ptr @b to i64), i64 3), i64 2147450880) to ptr) + %lshr2 = lshr i64 ptrtoint (ptr @b to i64), 3 + %add2 = add i64 %lshr2, 2147450880 + %inttoptr2 = inttoptr i64 %add2 to ptr + %61 = load i8, ptr %inttoptr2 %62 = icmp ne i8 %61, 0 br i1 %62, label %63, label %66 diff --git a/llvm/test/DebugInfo/AArch64/asan-stack-vars.mir b/llvm/test/DebugInfo/AArch64/asan-stack-vars.mir index 233ec00679aae..1b7159d5f0752 100644 --- a/llvm/test/DebugInfo/AArch64/asan-stack-vars.mir +++ b/llvm/test/DebugInfo/AArch64/asan-stack-vars.mir @@ -133,7 +133,8 @@ store i8* %_cmd, i8** %_cmd.addr, align 8 call void @llvm.dbg.declare(metadata i8** %_cmd.addr, metadata !48, metadata !DIExpression()), !dbg !47 %29 = load %struct._class_t*, %struct._class_t** @"OBJC_CLASSLIST_REFERENCES_$_", align 8, !dbg !50 - %30 = add i64 lshr (i64 ptrtoint (i8** @OBJC_SELECTOR_REFERENCES_ to i64), i64 3), %1, !dbg !50 + %lshr1 = lshr i64 ptrtoint (i8** @OBJC_SELECTOR_REFERENCES_ to i64), 3, !dbg !50 + %30 = add i64 %lshr1, %1, !dbg !50 %31 = inttoptr i64 %30 to i8*, !dbg !50 %32 = load i8, i8* %31, !dbg !50 %33 = icmp ne i8 %32, 0, !dbg !50 @@ -149,7 +150,8 @@ %37 = bitcast %struct._class_t* %29 to i8*, !dbg !50 %call = call i8* bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to i8* (i8*, i8*)*)(i8* %37, i8* %36), !dbg !50 %38 = bitcast i8* %call to %0*, !dbg !50 - %39 = add i64 lshr (i64 ptrtoint (i8** @OBJC_SELECTOR_REFERENCES_.2 to i64), i64 3), %1, !dbg !51 + %lshr2 = lshr i64 ptrtoint (i8** @OBJC_SELECTOR_REFERENCES_.2 to i64), 3, !dbg !51 + %39 = add i64 %lshr2, %1, !dbg !51 %40 = inttoptr i64 %39 to i8*, !dbg !51 %41 = load i8, i8* %40, !dbg !51 %42 = icmp ne i8 %41, 0, !dbg !51 @@ -197,7 +199,8 @@ ;