[all-commits] [llvm/llvm-project] da1938: [RISCV] Fold (X & -4096) == 0 -> (X >> 12) == 0 (#...

Craig Topper via All-commits all-commits at lists.llvm.org
Mon Aug 18 21:24:56 PDT 2025


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: da19383ae76d8483492cd52c26349ade8bfa4fbe
      https://github.com/llvm/llvm-project/commit/da19383ae76d8483492cd52c26349ade8bfa4fbe
  Author: Craig Topper <craig.topper at sifive.com>
  Date:   2025-08-18 (Mon, 18 Aug 2025)

  Changed paths:
    M llvm/lib/Target/RISCV/RISCVISelLowering.cpp
    M llvm/lib/Target/RISCV/RISCVInstrInfo.td
    M llvm/test/CodeGen/RISCV/and-negpow2-cmp.ll
    M llvm/test/CodeGen/RISCV/bittest.ll

  Log Message:
  -----------
  [RISCV] Fold (X & -4096) == 0 -> (X >> 12) == 0 (#154233)

This is a more general form of the recently added isel pattern
(seteq (i64 (and GPR:$rs1, 0x8000000000000000)), 0)
  -> (XORI (i64 (SRLI GPR:$rs1, 63)), 1)

We can use a shift right for any AND mask that is a negated power
of 2. But for every other constant we need to use seqz instead of
xori. I don't think there is a benefit to xori over seqz as neither
are compressible.

We already do this transform from target independent code when the setcc
constant is a non-zero subset of the AND mask that is not a legal icmp
immediate.

I don't believe any of these patterns comparing MSBs to 0 are
canonical according to InstCombine. The canonical form is (X < 4096).
I'm curious if these appear during SelectionDAG and if so, how.

My goal here was just to remove the special case isel patterns.



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list