[llvm] [RISCV] Teach getIntImmCostInst about X & -(1 << C1) & 0xffffffff) == C2 << C1 (PR #160163)

Piotr Fusik via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 22 11:52:26 PDT 2025


================
@@ -166,6 +166,42 @@ static bool canUseShiftPair(Instruction *Inst, const APInt &Imm) {
   return false;
 }
 
+// If this is a 64-bit AND with a mask of the form -(1 << C) in the lower 32
+// bits and the only user is an equality comparison, we might be able to use a
+// sraiw instead. This avoids the need to materialize the AND constant.
+static bool canUseSRAIWCmp(Instruction *Inst, const APInt &Imm) {
+  if (!Inst->hasOneUse())
----------------
pfusik wrote:

Multi-use doesn't seem much harder: just add a `for` loop and only `return true` after all users match.

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


More information about the llvm-commits mailing list