[llvm] r361169 - [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

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Mon May 20 09:27:09 PDT 2019


Author: ctopper
Date: Mon May 20 09:27:09 2019
New Revision: 361169

URL: http://llvm.org/viewvc/llvm-project?rev=361169&view=rev
Log:
[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

Modified:
    llvm/trunk/docs/LangRef.rst
    llvm/trunk/include/llvm/IR/Intrinsics.td
    llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
    llvm/trunk/lib/IR/Verifier.cpp

Modified: llvm/trunk/docs/LangRef.rst
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/docs/LangRef.rst?rev=361169&r1=361168&r2=361169&view=diff
==============================================================================
--- llvm/trunk/docs/LangRef.rst (original)
+++ llvm/trunk/docs/LangRef.rst Mon May 20 09:27:09 2019
@@ -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 sup
 
 ::
 
-      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:
 """"""""""

Modified: llvm/trunk/include/llvm/IR/Intrinsics.td
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/Intrinsics.td?rev=361169&r1=361168&r2=361169&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/Intrinsics.td (original)
+++ llvm/trunk/include/llvm/IR/Intrinsics.td Mon May 20 09:27:09 2019
@@ -539,9 +539,8 @@ let IntrProperties = [IntrNoMem, IntrSpe
   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],

Modified: llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp?rev=361169&r1=361168&r2=361169&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp (original)
+++ llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp Mon May 20 09:27:09 2019
@@ -6034,18 +6034,16 @@ void SelectionDAGBuilder::visitIntrinsic
                              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;

Modified: llvm/trunk/lib/IR/Verifier.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Verifier.cpp?rev=361169&r1=361168&r2=361169&view=diff
==============================================================================
--- llvm/trunk/lib/IR/Verifier.cpp (original)
+++ llvm/trunk/lib/IR/Verifier.cpp Mon May 20 09:27:09 2019
@@ -4620,6 +4620,14 @@ void Verifier::visitIntrinsicCall(Intrin
     }
     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;
+  }
   };
 }
 




More information about the llvm-commits mailing list