When have Zbs extension, we could use bexti to fold (and (not (srl X, C)), 1) to (xor (bexti X, C), 1).
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Unit Tests
Time | Test | |
---|---|---|
60 ms | x64 debian > LLVM.Bindings/Go::go.test |
Event Timeline
Have you seen real cases of this pattern? InstCombine canonicalizes this to (xor (and (srl X, C), 1), 1) before we get to SelectionDAG.
Yes. As you said, InstCombine do canonicalize this to xor (and (srl X, C), 1), 1 , but DAGCombine will also fold (xor (and x, y), y) -> (and (not x), y). So we still get and (not (srl X, C)), 1 in SelectionDAG. I will add another case xor (and (srl X, C), 1), 1 to show this.
llvm/lib/Target/RISCV/RISCVInstrInfoZb.td | ||
---|---|---|
795 | I wonder if the (XORI (BEXTI GPR:$rs1, $shamt), 1) we would have gotten from the original InstCombine canonicalization would be better. Guess it depends on whether the Zbs instructions are implemented as well as XORI or not. There is no c.xori or that would have been a good reason to favor xori. |
llvm/lib/Target/RISCV/RISCVInstrInfoZb.td | ||
---|---|---|
795 | Thanks, so that I could change DAGCombine to keep xor (and(srl X, C),1), 1 when we have single-Bit extract instruction in backend. In this situation, at least, we fold (and(srl X, C),1) into BEXTI X, C. What's your option about this? |
llvm/lib/Target/RISCV/RISCVInstrInfoZb.td | ||
---|---|---|
795 | Sorry, I misunderstanded your comment. Please ignore my last reply. I would simply change that pattern into def : Pat<(and (not (srl GPR:$rs1, uimmlog2xlen:$shamt)), (XLenVT 1)), (XORI (BEXTI GPR:$rs1, uimmlog2xlen:$shamt), (XLenVT 1)) |
llvm/test/CodeGen/RISCV/rv32zbs.ll | ||
---|---|---|
360 | sbexti->bexti I'll rename the existing test cases today. |
Update test case and change commit message.
llvm/test/CodeGen/RISCV/rv32zbs.ll | ||
---|---|---|
360 | Done. |
LGTM. Please fix the title to remove the mention of binvi since we aren't using that now.
I wonder if the (XORI (BEXTI GPR:$rs1, $shamt), 1) we would have gotten from the original InstCombine canonicalization would be better.
Guess it depends on whether the Zbs instructions are implemented as well as XORI or not. There is no c.xori or that would have been a good reason to favor xori.