// If we can use a BSET instruction, allow default promotion to apply.
if (N->getOpcode() == ISD::SHL && Subtarget.hasStdExtZbs() &&
isOneConstant(N->getOperand(0)))
break;
The defaults to BSET promotion given Zbs extension support.
This looks like a great minimal test case and a real issue - filing things like this as a bug is always a good way of ensuring it’s properly tracked. Thanks for spotting the problem.
I was just curious if this had been noticed and it was decided if bset promotion by default was worth it anyways as this is a small test case. I’ll look into a fix. I’m not sure how it would affect tests people might be running if we simply removed this and handled bset opts differently.
I really wish we’d gotten a bsetw instruction. The current hack works well when there is no mask on the shift amount and the upper bits of the result aren’t used by later instructions. If we let it become RISCVISD::SLLW we can’t turn it into BSET without adding an andi and a sext.w.
Maybe we can write an isel pattern for (sext (shl 1, (and X, 31))) and use sllw (li 1), X in that case.