[llvm] [X86] Don't assume the FPCLASS category mask is a literal (PR #213171)
Zane Hambly via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 4 06:45:41 PDT 2026
https://github.com/Zaneham updated https://github.com/llvm/llvm-project/pull/213171
>From 7e66d401efe75936c1044f3633c50944b3c88a31 Mon Sep 17 00:00:00 2001
From: Zane Hambly <zanehambly at gmail.com>
Date: Fri, 31 Jul 2026 02:16:36 +1200
Subject: [PATCH 1/3] [X86] Don't assume the FPCLASS category mask is a literal
---
.../X86/MCTargetDesc/X86InstComments.cpp | 5 +++++
llvm/test/MC/X86/symbolic-fpclass-imm.s | 21 +++++++++++++++++++
2 files changed, 26 insertions(+)
create mode 100644 llvm/test/MC/X86/symbolic-fpclass-imm.s
diff --git a/llvm/lib/Target/X86/MCTargetDesc/X86InstComments.cpp b/llvm/lib/Target/X86/MCTargetDesc/X86InstComments.cpp
index d7f21fe17bfe1..0ee814e786b44 100644
--- a/llvm/lib/Target/X86/MCTargetDesc/X86InstComments.cpp
+++ b/llvm/lib/Target/X86/MCTargetDesc/X86InstComments.cpp
@@ -1025,6 +1025,11 @@ static bool printFPCLASSComments(const MCInst *MI, raw_ostream &OS,
default:
return false;
}
+ // The category mask can be a symbol rather than a literal, in which case its
+ // value is only known at link time and there is no category to describe.
+ if (!MI->getOperand(NumOperands - 1).isImm())
+ return false;
+
StringRef DestName = getRegName(MI->getOperand(0).getReg());
StringRef SrcName =
SrcIdx != -1 ? getRegName(MI->getOperand(SrcIdx).getReg()) : "mem";
diff --git a/llvm/test/MC/X86/symbolic-fpclass-imm.s b/llvm/test/MC/X86/symbolic-fpclass-imm.s
new file mode 100644
index 0000000000000..8f4b70dbbdded
--- /dev/null
+++ b/llvm/test/MC/X86/symbolic-fpclass-imm.s
@@ -0,0 +1,21 @@
+// RUN: llvm-mc -triple x86_64-unknown-unknown -mattr=+avx512dq,+avx512vl %s | FileCheck %s
+// RUN: llvm-mc -triple x86_64-unknown-unknown -mattr=+avx512dq,+avx512vl --show-encoding %s | FileCheck %s --check-prefix=ENC
+
+// The FPCLASS category mask may be a symbol, whose value is only known at link
+// time. The instruction comment printer used to assume it was always a literal
+// and assert.
+
+// CHECK: vfpclassps $f0, %zmm1, %k1{{$}}
+// ENC: vfpclassps $f0, %zmm1, %k1
+// ENC-SAME: encoding: [0x62,0xf3,0x7d,0x48,0x66,0xc9,A]
+vfpclassps $f0, %zmm1, %k1
+
+// A literal category is still described as before.
+
+// CHECK: vfpclassps $3, %zmm1, %k1
+// CHECK-SAME: k1 = isQuietNaN(zmm1) | isPositiveZero(zmm1)
+vfpclassps $3, %zmm1, %k1
+
+// CHECK: vfpclassps $0, %zmm1, %k1
+// CHECK-SAME: k1 = false
+vfpclassps $0, %zmm1, %k1
>From ccf92aa85ad22853163fd6d7203dd390021b0571 Mon Sep 17 00:00:00 2001
From: Zane Hambly <zanehambly at gmail.com>
Date: Sun, 2 Aug 2026 00:20:54 +1200
Subject: [PATCH 2/3] Check the full line instead of CHECK-SAME
---
llvm/test/MC/X86/symbolic-fpclass-imm.s | 9 +++------
1 file changed, 3 insertions(+), 6 deletions(-)
diff --git a/llvm/test/MC/X86/symbolic-fpclass-imm.s b/llvm/test/MC/X86/symbolic-fpclass-imm.s
index 8f4b70dbbdded..091ba44513fe0 100644
--- a/llvm/test/MC/X86/symbolic-fpclass-imm.s
+++ b/llvm/test/MC/X86/symbolic-fpclass-imm.s
@@ -6,16 +6,13 @@
// and assert.
// CHECK: vfpclassps $f0, %zmm1, %k1{{$}}
-// ENC: vfpclassps $f0, %zmm1, %k1
-// ENC-SAME: encoding: [0x62,0xf3,0x7d,0x48,0x66,0xc9,A]
+// ENC: vfpclassps $f0, %zmm1, %k1 # encoding: [0x62,0xf3,0x7d,0x48,0x66,0xc9,A]
vfpclassps $f0, %zmm1, %k1
// A literal category is still described as before.
-// CHECK: vfpclassps $3, %zmm1, %k1
-// CHECK-SAME: k1 = isQuietNaN(zmm1) | isPositiveZero(zmm1)
+// CHECK: vfpclassps $3, %zmm1, %k1 # k1 = isQuietNaN(zmm1) | isPositiveZero(zmm1)
vfpclassps $3, %zmm1, %k1
-// CHECK: vfpclassps $0, %zmm1, %k1
-// CHECK-SAME: k1 = false
+// CHECK: vfpclassps $0, %zmm1, %k1 # k1 = false
vfpclassps $0, %zmm1, %k1
>From 1150f3d538c5bcdf780da0d281d228eb69bc6526 Mon Sep 17 00:00:00 2001
From: ZaneHam <zanehambly at gmail.com>
Date: Wed, 5 Aug 2026 01:36:15 +1200
Subject: [PATCH 3/3] Use only the --show-encoding RUN line
---
llvm/test/MC/X86/symbolic-fpclass-imm.s | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/llvm/test/MC/X86/symbolic-fpclass-imm.s b/llvm/test/MC/X86/symbolic-fpclass-imm.s
index 091ba44513fe0..08894d04b93fa 100644
--- a/llvm/test/MC/X86/symbolic-fpclass-imm.s
+++ b/llvm/test/MC/X86/symbolic-fpclass-imm.s
@@ -1,18 +1,19 @@
-// RUN: llvm-mc -triple x86_64-unknown-unknown -mattr=+avx512dq,+avx512vl %s | FileCheck %s
-// RUN: llvm-mc -triple x86_64-unknown-unknown -mattr=+avx512dq,+avx512vl --show-encoding %s | FileCheck %s --check-prefix=ENC
+// RUN: llvm-mc -triple x86_64-unknown-unknown -mattr=+avx512dq,+avx512vl --show-encoding %s | FileCheck %s
// The FPCLASS category mask may be a symbol, whose value is only known at link
// time. The instruction comment printer used to assume it was always a literal
// and assert.
-// CHECK: vfpclassps $f0, %zmm1, %k1{{$}}
-// ENC: vfpclassps $f0, %zmm1, %k1 # encoding: [0x62,0xf3,0x7d,0x48,0x66,0xc9,A]
+// CHECK: vfpclassps $f0, %zmm1, %k1 # encoding: [0x62,0xf3,0x7d,0x48,0x66,0xc9,A]
+// CHECK-NEXT: fixup A - offset: 6, value: f0, kind: FK_Data_1
vfpclassps $f0, %zmm1, %k1
// A literal category is still described as before.
-// CHECK: vfpclassps $3, %zmm1, %k1 # k1 = isQuietNaN(zmm1) | isPositiveZero(zmm1)
+// CHECK: vfpclassps $3, %zmm1, %k1 # encoding: [0x62,0xf3,0x7d,0x48,0x66,0xc9,0x03]
+// CHECK-NEXT: # k1 = isQuietNaN(zmm1) | isPositiveZero(zmm1)
vfpclassps $3, %zmm1, %k1
-// CHECK: vfpclassps $0, %zmm1, %k1 # k1 = false
+// CHECK: vfpclassps $0, %zmm1, %k1 # encoding: [0x62,0xf3,0x7d,0x48,0x66,0xc9,0x00]
+// CHECK-NEXT: # k1 = false
vfpclassps $0, %zmm1, %k1
More information about the llvm-commits
mailing list