This hook is currently only used by CodeGenPrepare, which will sink an
and into a block that has an icmp 0 user of it.
This hook is less useful for RISC-V than for targets like AArch64 that
have a TBZ (test bit and branch if zero instruction), but may still be
profitable if Zbs is available and a BEXTI can be selected.
Conservatively, we return false even if Zbs is enabled for any masks
that fit in the ANDI immediate because it's possible the only use is a
branch on the result, and ANDI+BNEZ => BEXTI+BNEZ isn't a profitable
transformation.
This bit of logic feels like you're covering up something else. Moving around the and instruction in IR shouldn't directly cause the bexti to be used if the andi form is legal and profitable. Do we maybe have a missing pattern?
As a guess, maybe this is intersecting with D131482?