[llvm] [AsmParser] Allow comparing ValIDs with different kinds (PR #119834)

Yingwei Zheng via llvm-commits llvm-commits at lists.llvm.org
Fri Dec 13 03:05:46 PST 2024


https://github.com/dtcxzyw updated https://github.com/llvm/llvm-project/pull/119834

>From 059e4eb6a65629ae9fd236dbe912c18be19e3e65 Mon Sep 17 00:00:00 2001
From: Yingwei Zheng <dtcxzyw2333 at gmail.com>
Date: Fri, 13 Dec 2024 15:42:48 +0800
Subject: [PATCH 1/2] [LLParser] Allow comparing ValIDs with different kinds

---
 llvm/include/llvm/AsmParser/LLParser.h | 11 +++++++----
 llvm/test/Assembler/pr119818.ll        | 23 +++++++++++++++++++++++
 2 files changed, 30 insertions(+), 4 deletions(-)
 create mode 100644 llvm/test/Assembler/pr119818.ll

diff --git a/llvm/include/llvm/AsmParser/LLParser.h b/llvm/include/llvm/AsmParser/LLParser.h
index 1ef8b8ffc39660..8b195b028783f0 100644
--- a/llvm/include/llvm/AsmParser/LLParser.h
+++ b/llvm/include/llvm/AsmParser/LLParser.h
@@ -91,12 +91,15 @@ namespace llvm {
     }
 
     bool operator<(const ValID &RHS) const {
-      assert(Kind == RHS.Kind && "Comparing ValIDs of different kinds");
+      assert((((Kind == t_LocalID || Kind == t_LocalName) &&
+               (RHS.Kind == t_LocalID || RHS.Kind == t_LocalName)) ||
+              ((Kind == t_GlobalID || Kind == t_GlobalName) &&
+               (RHS.Kind == t_GlobalID || RHS.Kind == t_GlobalName))) &&
+             "Comparing ValIDs of different kinds");
+      if (Kind != RHS.Kind)
+        return Kind < RHS.Kind;
       if (Kind == t_LocalID || Kind == t_GlobalID)
         return UIntVal < RHS.UIntVal;
-      assert((Kind == t_LocalName || Kind == t_GlobalName ||
-              Kind == t_ConstantStruct || Kind == t_PackedConstantStruct) &&
-             "Ordering not defined for this ValID kind yet");
       return StrVal < RHS.StrVal;
     }
   };
diff --git a/llvm/test/Assembler/pr119818.ll b/llvm/test/Assembler/pr119818.ll
new file mode 100644
index 00000000000000..38b732f9ec298c
--- /dev/null
+++ b/llvm/test/Assembler/pr119818.ll
@@ -0,0 +1,23 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
+; RUN: opt -S < %s | FileCheck %s
+
+ at vm_exec_core.insns_address_table = internal constant [2 x ptr] [ptr blockaddress(@vm_exec_core, %2), ptr blockaddress(@vm_exec_core, %.lr.ph.i2526)], align 16
+
+define void @vm_exec_core() {
+; CHECK-LABEL: define void @vm_exec_core() {
+; CHECK-NEXT:  [[ENTRY:.*:]]
+; CHECK-NEXT:    br [[DOTLR_PH_I2526:label %.*]]
+; CHECK:       [[_LR_PH_I2526:.*:]]
+; CHECK-NEXT:    br label %[[BB0:.*]]
+; CHECK:       [[BB0]]:
+; CHECK-NEXT:    ret void
+;
+entry:
+  br label %.lr.ph.i2526
+
+.lr.ph.i2526:
+  br label %2
+
+2:
+  ret void
+}

>From a3e427ad5bc2fe57f3b015d4a3c61f5ae21f68a1 Mon Sep 17 00:00:00 2001
From: Yingwei Zheng <dtcxzyw2333 at gmail.com>
Date: Fri, 13 Dec 2024 19:04:53 +0800
Subject: [PATCH 2/2] [AsmParser] Rename BBs. NFC.

---
 llvm/test/Assembler/pr119818.ll | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/llvm/test/Assembler/pr119818.ll b/llvm/test/Assembler/pr119818.ll
index 38b732f9ec298c..568648424e4ac6 100644
--- a/llvm/test/Assembler/pr119818.ll
+++ b/llvm/test/Assembler/pr119818.ll
@@ -1,23 +1,23 @@
 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
 ; RUN: opt -S < %s | FileCheck %s
 
- at vm_exec_core.insns_address_table = internal constant [2 x ptr] [ptr blockaddress(@vm_exec_core, %2), ptr blockaddress(@vm_exec_core, %.lr.ph.i2526)], align 16
+ at vm_exec_core.insns_address_table = internal constant [2 x ptr] [ptr blockaddress(@vm_exec_core, %0), ptr blockaddress(@vm_exec_core, %block)], align 16
 
 define void @vm_exec_core() {
 ; CHECK-LABEL: define void @vm_exec_core() {
 ; CHECK-NEXT:  [[ENTRY:.*:]]
-; CHECK-NEXT:    br [[DOTLR_PH_I2526:label %.*]]
-; CHECK:       [[_LR_PH_I2526:.*:]]
+; CHECK-NEXT:    br label %[[BLOCK:.*]]
+; CHECK:       [[BLOCK]]:
 ; CHECK-NEXT:    br label %[[BB0:.*]]
 ; CHECK:       [[BB0]]:
 ; CHECK-NEXT:    ret void
 ;
 entry:
-  br label %.lr.ph.i2526
+  br label %block
 
-.lr.ph.i2526:
-  br label %2
+block:
+  br label %0
 
-2:
+0:
   ret void
 }



More information about the llvm-commits mailing list