[llvm] Added InvertedFPClassTest in legalizerHelper (PR #133403)

via llvm-commits llvm-commits at lists.llvm.org
Sun Mar 30 12:31:27 PDT 2025


https://github.com/sumesh-s-mcw updated https://github.com/llvm/llvm-project/pull/133403

>From b39e0640406590ca8625287da510f186faa5c43a Mon Sep 17 00:00:00 2001
From: sumesh-s-mcw <sumesh.suresh at multicorewareinc.com>
Date: Mon, 31 Mar 2025 00:47:07 +0530
Subject: [PATCH] FEAT : Added InvertedFPClassTest in LegalizerHelper

---
 llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp b/llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp
index ac68eb55a6fd5..cef6f446f9854 100644
--- a/llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp
+++ b/llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp
@@ -13,6 +13,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "llvm/CodeGen/GlobalISel/LegalizerHelper.h"
+#include "llvm/CodeGen/CodeGenCommonISel.h"
 #include "llvm/CodeGen/GlobalISel/CallLowering.h"
 #include "llvm/CodeGen/GlobalISel/GISelChangeObserver.h"
 #include "llvm/CodeGen/GlobalISel/GISelValueTracking.h"
@@ -9100,8 +9101,12 @@ LegalizerHelper::lowerISFPCLASS(MachineInstr &MI) {
     return Legalized;
   }
 
-  // TODO: Try inverting the test with getInvertedFPClassTest like the DAG
-  // version
+  bool isInverted = false;
+  FPClassTest InvertedTest = llvm::invertFPClassTestIfSimpler(Mask, false);
+  if (Inverse != fcNone) {
+    Mask = InvertedTest;
+    isInverted = true;
+  }
 
   unsigned BitSize = SrcTy.getScalarSizeInBits();
   const fltSemantics &Semantics = getFltSemanticForLLT(SrcTy.getScalarType());
@@ -9252,7 +9257,9 @@ LegalizerHelper::lowerISFPCLASS(MachineInstr &MI) {
     }
     appendToRes(NormalRes);
   }
-
+  if (isInverted) {
+    Res = MIRBuilder.buildNot(DstTy, Res);
+  }
   MIRBuilder.buildCopy(DstReg, Res);
   MI.eraseFromParent();
   return Legalized;



More information about the llvm-commits mailing list