[llvm] [RISCV] Porting hasAllNBitUsers to RISCV GISel for instruction select (PR #125795)

Luke Quinn via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 5 06:27:22 PST 2025


================
@@ -184,6 +198,79 @@ RISCVInstructionSelector::RISCVInstructionSelector(
 {
 }
 
+// Mimics optimizations in ISel and RISCVOptWInst Pass
+bool RISCVInstructionSelector::hasAllNBitUsers(const MachineInstr &MI,
+                                               unsigned Bits,
+                                               const unsigned Depth) const {
+
+  assert((MI.getOpcode() == TargetOpcode::G_ADD ||
+          MI.getOpcode() == TargetOpcode::G_SUB ||
+          MI.getOpcode() == TargetOpcode::G_MUL ||
+          MI.getOpcode() == TargetOpcode::G_SHL ||
+          MI.getOpcode() == TargetOpcode::G_LSHR ||
+          MI.getOpcode() == TargetOpcode::G_AND ||
+          MI.getOpcode() == TargetOpcode::G_OR ||
+          MI.getOpcode() == TargetOpcode::G_XOR ||
+          MI.getOpcode() == TargetOpcode::G_SEXT_INREG || Depth != 0) &&
----------------
lquinn2015 wrote:

>From a code flow perspective at least in GISel currently the only entry point for the hasAllNBitUsers comes from the binop_allhusers and binop_allwusers  i.e not Constants. I think ISel  Dag to Dag might call this in other locations with a SDNodeConstant type but GISel definitely does not have that. 

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


More information about the llvm-commits mailing list