This is an archive of the discontinued LLVM Phabricator instance.

[RISCV] Omit SRA in case of setlt or setge with zero constant
ClosedPublic

Authored by eklepilkina on Dec 16 2022, 4:46 AM.

Details

Summary

As far as arithmetic right shift always saves the sign, shift can be omitted to check if number is positive or negative.

Diff Detail

Event Timeline

eklepilkina created this revision.Dec 16 2022, 4:46 AM
Herald added a project: Restricted Project. · View Herald TranscriptDec 16 2022, 4:46 AM
eklepilkina requested review of this revision.Dec 16 2022, 4:46 AM
eklepilkina edited the summary of this revision. (Show Details)Dec 16 2022, 4:50 AM
eklepilkina added a reviewer: craig.topper.
eklepilkina added a subscriber: anton-afanasyev.

During fixing this case I had a question why RISCV doesn't use SimplifySetCC from common TargetLowering. It seems that there are some cases of combinations that should work for RISCV. I tried to call it, but found cases that crashes compilations on RISCV. Are there any plans to rework this part and reuse some part of foldings from common lowering? It seems that some optimizations can be lost, doesn't it?

eklepilkina retitled this revision from [RISCV] Ommit SRA in case of setlt or setge with zero constant to [RISCV] Omit SRA in case of setlt or setge with zero constant.Dec 16 2022, 7:09 AM

During fixing this case I had a question why RISCV doesn't use SimplifySetCC from common TargetLowering. It seems that there are some cases of combinations that should work for RISCV. I tried to call it, but found cases that crashes compilations on RISCV. Are there any plans to rework this part and reuse some part of foldings from common lowering? It seems that some optimizations can be lost, doesn't it?

It should be called from DAGCombiner both before and after type legalization. I think the issue here is that the setcc is merged into RISCVISD::BR_CC before the sign_extend_inreg is converted to shl+sra.

craig.topper added inline comments.Dec 18 2022, 9:51 PM
llvm/test/CodeGen/RISCV/branch_zero.ll
11

Can you construct a test for GE too?

This revision is now accepted and ready to land.Dec 19 2022, 12:10 PM
This revision was landed with ongoing or failed builds.Dec 21 2022, 3:20 AM
This revision was automatically updated to reflect the committed changes.