[clang] [llvm] [IR] Use pretty printing for mask in is_fpclass (PR #207653)

Antonio Frighetto via cfe-commits cfe-commits at lists.llvm.org
Thu Jul 9 00:36:00 PDT 2026


================
@@ -1472,6 +1472,60 @@ Intrinsic::ID Intrinsic::getDeinterleaveIntrinsicID(unsigned Factor) {
   return InterleaveIntrinsics[Factor - 2].Deinterleave;
 }
 
+LLVM_ABI void Intrinsic::printFPClassMask(raw_ostream &OS,
+                                          const Constant *ImmArgVal) {
+  if (const auto *CI = dyn_cast<ConstantInt>(ImmArgVal)) {
+    uint64_t Val = CI->getZExtValue();
+    if (Val <= fcAllFlags) {
+      SmallVector<StringRef, 5> Classes;
+      if (Val & fcZero) {
+        if ((Val & fcZero) == fcZero)
+          Classes.push_back("zero");
+        else if (Val & fcPosZero)
+          Classes.push_back("+zero");
+        else
+          Classes.push_back("-zero");
+      }
+      if (Val & fcSubnormal) {
+        if ((Val & fcSubnormal) == fcSubnormal)
+          Classes.push_back("subnormal");
+        else if (Val & fcPosSubnormal)
+          Classes.push_back("+subnormal");
+        else
+          Classes.push_back("-subnormal");
+      }
+      if (Val & fcNormal) {
+        if ((Val & fcNormal) == fcNormal)
+          Classes.push_back("normal");
+        else if (Val & fcPosNormal)
+          Classes.push_back("+normal");
+        else
+          Classes.push_back("-normal");
+      }
+      if (Val & fcInf) {
+        if ((Val & fcInf) == fcInf)
+          Classes.push_back("inf");
+        else if (Val & fcPosInf)
+          Classes.push_back("+inf");
+        else
+          Classes.push_back("-inf");
+      }
+      if (Val & fcNan) {
+        if ((Val & fcNan) == fcNan)
+          Classes.push_back("nan");
+        else if (Val & fcQNan)
+          Classes.push_back("qnan");
+        else
+          Classes.push_back("snan");
+      }
+      OS << llvm::join(Classes, "|");
----------------
antoniofrighetto wrote:

Not strong on this either, but somehow I find the `|` separators a little bit jarring, whereas the commas inside the comment might visually blur into the commas that separate function arguments. I'd also lean towards space separators.

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


More information about the cfe-commits mailing list