[llvm] AMDGPU: Add tonearest and towardzero roundings for intrinsic llvm.fptrunc.round (PR #104486)

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 16 11:06:15 PDT 2024


================
@@ -7089,23 +7089,29 @@ bool AMDGPULegalizerInfo::legalizeBVHIntrinsic(MachineInstr &MI,
 }
 
 bool AMDGPULegalizerInfo::legalizeFPTruncRound(MachineInstr &MI,
+                                               MachineRegisterInfo &MRI,
                                                MachineIRBuilder &B) const {
-  unsigned Opc;
-  int RoundMode = MI.getOperand(2).getImm();
+  Register Src = MI.getOperand(1).getReg();
+  if (MRI.getType(Src) != LLT::scalar(32))
+    return false;
 
-  if (RoundMode == (int)RoundingMode::TowardPositive)
-    Opc = AMDGPU::G_FPTRUNC_ROUND_UPWARD;
-  else if (RoundMode == (int)RoundingMode::TowardNegative)
-    Opc = AMDGPU::G_FPTRUNC_ROUND_DOWNWARD;
-  else
+  // Only support towardzero, tonearest, upward and downward.
+  int RoundMode = MI.getOperand(2).getImm();
+  if (RoundMode < (int)RoundingMode::TowardZero ||
+      RoundMode > (int)RoundingMode::TowardNegative)
----------------
arsenm wrote:

Do exact equality checks for the supported modes 

https://github.com/llvm/llvm-project/pull/104486


More information about the llvm-commits mailing list