From: Craig Topper Date: Mon, 20 May 2019 16:27:09 +0000 (+0000) Subject: [Intrinsics] Merge lround.i32 and lround.i64 into a single intrinsic with overloaded... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1d3fa78b07129f53c4fe30803f701f134846f4ec;p=llvm [Intrinsics] Merge lround.i32 and lround.i64 into a single intrinsic with overloaded result type. Make result type for llvm.llround overloaded instead of fixing to i64 We shouldn't really make assumptions about possible sizes for long and long long. And longer term we should probably support vectorizing these intrinsics. By making the result types not fixed we can support vectors as well. Differential Revision: https://reviews.llvm.org/D62026 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@361169 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/docs/LangRef.rst b/docs/LangRef.rst index 07d755c1d78..3f35752b450 100644 --- a/docs/LangRef.rst +++ b/docs/LangRef.rst @@ -12398,8 +12398,7 @@ nearest integer. Arguments: """""""""" -The argument is a floating-point number and return is i32 for -``llvm.lround.i32`` and i64 for ``llvm.lround.i64``. +The argument is a floating-point number and return is an integer type. Semantics: """""""""" @@ -12418,11 +12417,11 @@ floating-point type. Not all targets support all types however. :: - declare i64 @llvm.lround.f32(float %Val) - declare i64 @llvm.lround.f64(double %Val) - declare i64 @llvm.lround.f80(float %Val) - declare i64 @llvm.lround.f128(double %Val) - declare i64 @llvm.lround.ppcf128(double %Val) + declare i64 @llvm.lround.i64.f32(float %Val) + declare i64 @llvm.lround.i64.f64(double %Val) + declare i64 @llvm.lround.i64.f80(float %Val) + declare i64 @llvm.lround.i64.f128(double %Val) + declare i64 @llvm.lround.i64.ppcf128(double %Val) Overview: """"""""" @@ -12433,7 +12432,7 @@ nearest integer. Arguments: """""""""" -The argument is a floating-point number and return is i64. +The argument is a floating-point number and return is an integer type. Semantics: """""""""" diff --git a/include/llvm/IR/Intrinsics.td b/include/llvm/IR/Intrinsics.td index a1e37b66c5f..2957478ef5b 100644 --- a/include/llvm/IR/Intrinsics.td +++ b/include/llvm/IR/Intrinsics.td @@ -539,9 +539,8 @@ let IntrProperties = [IntrNoMem, IntrSpeculatable] in { def int_canonicalize : Intrinsic<[llvm_anyfloat_ty], [LLVMMatchType<0>], [IntrNoMem]>; - def int_lround_i32 : Intrinsic<[llvm_i32_ty], [llvm_anyfloat_ty]>; - def int_lround_i64 : Intrinsic<[llvm_i64_ty], [llvm_anyfloat_ty]>; - def int_llround : Intrinsic<[llvm_i64_ty], [llvm_anyfloat_ty]>; + def int_lround : Intrinsic<[llvm_anyint_ty], [llvm_anyfloat_ty]>; + def int_llround : Intrinsic<[llvm_anyint_ty], [llvm_anyfloat_ty]>; } def int_minnum : Intrinsic<[llvm_anyfloat_ty], diff --git a/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp b/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp index 938aeafb435..33980040051 100644 --- a/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp +++ b/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp @@ -6034,18 +6034,16 @@ void SelectionDAGBuilder::visitIntrinsicCall(const CallInst &I, getValue(I.getArgOperand(0)))); return; } - case Intrinsic::lround_i32: - case Intrinsic::lround_i64: + case Intrinsic::lround: case Intrinsic::llround: { unsigned Opcode; - MVT RetVT; switch (Intrinsic) { default: llvm_unreachable("Impossible intrinsic"); // Can't reach here. - case Intrinsic::lround_i32: Opcode = ISD::LROUND; RetVT = MVT::i32; break; - case Intrinsic::lround_i64: Opcode = ISD::LROUND; RetVT = MVT::i64; break; - case Intrinsic::llround: Opcode = ISD::LLROUND; RetVT = MVT::i64; break; + case Intrinsic::lround: Opcode = ISD::LROUND; break; + case Intrinsic::llround: Opcode = ISD::LLROUND; break; } + EVT RetVT = TLI.getValueType(DAG.getDataLayout(), I.getType()); setValue(&I, DAG.getNode(Opcode, sdl, RetVT, getValue(I.getArgOperand(0)))); return; diff --git a/lib/IR/Verifier.cpp b/lib/IR/Verifier.cpp index f7004cf4eae..67d43ce7740 100644 --- a/lib/IR/Verifier.cpp +++ b/lib/IR/Verifier.cpp @@ -4620,6 +4620,14 @@ void Verifier::visitIntrinsicCall(Intrinsic::ID ID, CallBase &Call) { } break; } + case Intrinsic::lround: + case Intrinsic::llround: { + Type *ValTy = Call.getArgOperand(0)->getType(); + Type *ResultTy = Call.getType(); + Assert(!ValTy->isVectorTy() && !ResultTy->isVectorTy(), + "Intrinsic does not support vectors", &Call); + break; + } }; }