This patch optimizes (and r i) to
(BCLRI (BCLRI r, i0), i1) in which i = ~((1<<i0) | (1<<i1)).
or
(BCLRI (ANDI r, i0), i1) in which i = i0 & ~(1<<i1).
Details
Diff Detail
Event Timeline
llvm/lib/Target/RISCV/RISCVInstrInfoB.td | ||
---|---|---|
140 | What if the type is i32 and bit 31 is one of the clear bits. This sign extend won't handle that case. |
llvm/lib/Target/RISCV/RISCVInstrInfoB.td | ||
---|---|---|
140 | I have handled the special case you concerned, and two tests are added along, which show improvements of the special case. It is not needed to pre-commit the tests, since the difference among the pattern RV32I, RV32IB and RV32IBS shows this improvement. |
Are you planning on extending this to use bclriw on RV64? (Would that clash with the use of tablegen? Personally, I tend to find C++ custom lowering of longer stuff easier to read and more cohesive, not sure how others feel)
llvm/lib/Target/RISCV/RISCVInstrInfoB.td | ||
---|---|---|
140 | Drop the explicit cast to uint64_t? | |
141–143 | I found this a bit confusing when I first read it. I suppose an alternative would be to replace the three lines with something like return countPopulation(I) == XLen - 2? |
I have not consider BSETIW/BINVIW/BCLRIW, maybe I will do it in next patch. And this patch will just focuses on BCLRI.
I do not like C++ custom lowering for that, since it needs even more lines than current form.
What if the type is i32 and bit 31 is one of the clear bits. This sign extend won't handle that case.