[llvm] [DirectX] Implement `llvm.is.fpclass` lowering for the fcNegZero FPClassTest and the `IsNaN`, `IsInf`, `IsFinite`, `IsNormal` DXIL ops (PR #138048)

Farzon Lotfi via llvm-commits llvm-commits at lists.llvm.org
Fri May 2 05:54:23 PDT 2025


================
@@ -739,6 +739,47 @@ class OpLowerer {
     });
   }
 
+  [[nodiscard]] bool lowerIsFPClass(Function &F) {
+    IRBuilder<> &IRB = OpBuilder.getIRB();
+    Type *RetTy = IRB.getInt1Ty();
+
+    return replaceFunction(F, [&](CallInst *CI) -> Error {
+      IRB.SetInsertPoint(CI);
+      SmallVector<Value *> Args;
+      Value *Fl = CI->getArgOperand(0);
+      Args.push_back(Fl);
+
+      dxil::OpCode OpCode;
+      Value *T = CI->getArgOperand(1);
+      auto *TCI = dyn_cast<ConstantInt>(T);
+      switch (TCI->getZExtValue()) {
+      case FPClassTest::fcInf:
+        OpCode = dxil::OpCode::IsInf;
+        break;
+      case FPClassTest::fcNan:
+        OpCode = dxil::OpCode::IsNaN;
+        break;
+      case FPClassTest::fcNormal:
+        OpCode = dxil::OpCode::IsNormal;
+        break;
+      case FPClassTest::fcFinite:
+        OpCode = dxil::OpCode::IsFinite;
+        break;
+      default:
+        llvm_unreachable("Unsupported FPClassTest for DXILOpLowering");
----------------
farzonl wrote:

none of the other error cases in `DXILOpLowering.cpp` are using  `llvm_unreachable` should we do `M.getContext().emitError(Msg);` instead?

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


More information about the llvm-commits mailing list