[llvm] [RISCV] Add bset optimization for left shift code (PR #71420)

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 6 22:44:10 PST 2023


================
@@ -554,6 +554,8 @@ def : Pat<(XLenVT (and (shiftop<srl> GPR:$rs1, (XLenVT GPR:$rs2)), 1)),
 
 def : Pat<(XLenVT (shiftop<shl> 1, (XLenVT GPR:$rs2))),
           (BSET (XLenVT X0), GPR:$rs2)>;
+def : Pat<(XLenVT (xor (shiftopw<riscv_sllw> -1, (XLenVT GPR:$rs2)), -1)),
----------------
topperc wrote:

Finally at a computer and not on my phone. My concern is that we will compile this example without an `andi reg, reg, 31` that would be needed with bset but not with sllw. It's really unfortunate that there is no bsetw.

```
define signext i32 @bset_i32_not_mask(i32 signext %a) nounwind {
  %mask = and i32 %a, 31
  %notmask = shl nsw i32 -1, %a
  %sub = xor i32 %notmask, -1
  ret i32 %sub
}
```

https://godbolt.org/z/WcnE577K1

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


More information about the llvm-commits mailing list