The result of sub + setcc is 0 or 1 for all bits.
The sra instruction get the same result.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
This is not correct for the add cases
A correct transform would be
fold (add (setcc x, 0, setlt), -1) -> (xor (sra x, xlen - 1), -1)
fold (add (setcc 0, x, setgt), -1) -> (xor (sra x, xlen - 1), -1)
But I'm not sure that's profitable.
llvm/lib/Target/RISCV/RISCVISelLowering.cpp | ||
---|---|---|
9116 | You can delete the setgt code. It will never exist in that form. Prior to LegalizeDAG we keep constants on the RHS of setcc. LegalizeDAG won't have any reason to change it. The only case that should have 0 on the left hand side is (setcc 0, x, setlt) which we get from legalizing (setcc x, 0, setgt). |
LGTM with that comment addressed.
llvm/lib/Target/RISCV/RISCVISelLowering.cpp | ||
---|---|---|
9113 | Move VT and DL inside the ifs since they aren't used until getNode. |
Move VT and DL inside the ifs since they aren't used until getNode.