[llvm] [RISCV] Add SimplifyDemandedBits and hasAllNBitUsers support for CLSW. (PR #174542)

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 5 23:55:07 PST 2026


https://github.com/topperc created https://github.com/llvm/llvm-project/pull/174542

This matches what we do for CLZW and other W instructions.

>From 8bbfc3898f2b35bccf4aa431ce5c00b8724da4c2 Mon Sep 17 00:00:00 2001
From: Craig Topper <craig.topper at sifive.com>
Date: Mon, 5 Jan 2026 23:53:42 -0800
Subject: [PATCH] [RISCV] Add SimplifyDemandedBits and hasAllNBitUsers support
 for CLSW.

This matches what we do for CLZW and other W instructions.
---
 llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp | 1 +
 llvm/lib/Target/RISCV/RISCVISelLowering.cpp | 1 +
 llvm/lib/Target/RISCV/RISCVOptWInstrs.cpp   | 1 +
 3 files changed, 3 insertions(+)

diff --git a/llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp b/llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp
index e2d6d37d8f6e3..b51ed9cddbeb2 100644
--- a/llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp
+++ b/llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp
@@ -4085,6 +4085,7 @@ bool RISCVDAGToDAGISel::hasAllNBitUsers(SDNode *Node, unsigned Bits,
     case RISCV::ROLW:
     case RISCV::RORW:
     case RISCV::RORIW:
+    case RISCV::CLSW:
     case RISCV::CLZW:
     case RISCV::CTZW:
     case RISCV::CPOPW:
diff --git a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
index 1ebc7235a74e5..363efd5e0a3dc 100644
--- a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
+++ b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
@@ -20909,6 +20909,7 @@ SDValue RISCVTargetLowering::PerformDAGCombine(SDNode *N,
     break;
   }
   case RISCVISD::ABSW:
+  case RISCVISD::CLSW:
   case RISCVISD::CLZW:
   case RISCVISD::CTZW: {
     // Only the lower 32 bits of the first operand are read
diff --git a/llvm/lib/Target/RISCV/RISCVOptWInstrs.cpp b/llvm/lib/Target/RISCV/RISCVOptWInstrs.cpp
index ea98cdb4a1e67..8baae84111a9c 100644
--- a/llvm/lib/Target/RISCV/RISCVOptWInstrs.cpp
+++ b/llvm/lib/Target/RISCV/RISCVOptWInstrs.cpp
@@ -168,6 +168,7 @@ static bool hasAllNBitUsers(const MachineInstr &OrigMI,
       case RISCV::ROLW:
       case RISCV::RORW:
       case RISCV::RORIW:
+      case RISCV::CLSW:
       case RISCV::CLZW:
       case RISCV::CTZW:
       case RISCV::CPOPW:



More information about the llvm-commits mailing list