[PATCH] D151803: [GlobalIsel][X86] Legalize G_BSWAP II

Thorsten via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 1 10:46:48 PDT 2023


tschuett updated this revision to Diff 527500.
tschuett added a comment.

second attempt


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D151803/new/

https://reviews.llvm.org/D151803

Files:
  llvm/lib/Target/X86/X86LegalizerInfo.cpp


Index: llvm/lib/Target/X86/X86LegalizerInfo.cpp
===================================================================
--- llvm/lib/Target/X86/X86LegalizerInfo.cpp
+++ llvm/lib/Target/X86/X86LegalizerInfo.cpp
@@ -98,6 +98,53 @@
   getActionDefinitionsBuilder({G_MEMCPY, G_MEMMOVE, G_MEMSET}).libcall();
 
 
+  if (Subtarget.is64Bit()) {
+    getActionDefinitionsBuilder(G_BSWAP)
+      .legalFor({s32, s64})
+      .widenScalarToNextPow2(0, /*Min=*/32)
+      .clampScalar(0, s32, s64);
+
+    if (Subtarget.hasPOPCNT()) {
+      // popcount (POPCNT)
+      getActionDefinitionsBuilder(G_CTPOP)
+        .legalFor({{s16, s16}, {s32, s32}, {s64, s64}})
+        .widenScalarToNextPow2(1, /*Min=*/16)
+        .clampScalar(1, s16, s64);
+    }
+
+    if (Subtarget.hasLZCNT()) {
+      // count leading zeros (LZCNT)
+      getActionDefinitionsBuilder(G_CTLZ)
+        .legalFor({{s16, s16}, {s32, s32}, {s64, s64}})
+        .widenScalarToNextPow2(1, /*Min=*/16)
+        .clampScalar(1, s16, s64);
+    }
+  } else { // 32-bit
+    getActionDefinitionsBuilder(G_BSWAP)
+      .legalIf([=](const LegalityQuery &Query) {
+        // workaround for legalFor
+        return Query.Types[0] == s32;
+      })
+      .widenScalarToNextPow2(0, /*Min=*/32)
+      .clampScalar(0, s32, s32);
+
+    if (Subtarget.hasPOPCNT()) {
+      // popcount
+      getActionDefinitionsBuilder(G_CTPOP)
+        .legalFor({{s16, s16}, {s32, s32}})
+        .widenScalarToNextPow2(1, /*Min=*/16)
+        .clampScalar(1, s16, s32);
+    }
+
+    if (Subtarget.hasLZCNT()) {
+      // count leading zeros (LZCNT)
+      getActionDefinitionsBuilder(G_CTLZ)
+        .legalFor({{s16, s16}, {s32, s32}})
+        .widenScalarToNextPow2(1, /*Min=*/16)
+        .clampScalar(1, s16, s32);
+    }
+  }
+
   LegacyInfo.computeTables();
   verify(*STI.getInstrInfo());
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D151803.527500.patch
Type: text/x-patch
Size: 1838 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230601/eb6d8e8e/attachment.bin>


More information about the llvm-commits mailing list