[llvm] [SimplifyCFG] Don't limit the number of simultaneous forwards from switch condition (PR #95932)

via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 19 05:58:11 PDT 2024


DianQK wrote:

Thank you for your explanation. However, I still think is meaningful.

I've chosen some examples to demonstrate the final results in assembly code. Analyzing more practical changes might be challenging, so I'm comparing the number of instructions, which might not be ideal but should at least show that this transformation is not harmful.

- I replaced `undef` with other values, and this transformation resulted in a slight increase in instructions: https://alive2.llvm.org/ce/z/2yE6g_, but, on arm64, the instruction count remains the same.: https://alive2.llvm.org/ce/z/zMVH2_
- I continued by modifying the switch conditions with other values, which reduced some instructions: https://alive2.llvm.org/ce/z/y2Xa8k (Similarly for arm64: https://alive2.llvm.org/ce/z/mfKixU)
- I removed some code, which I believe is an improvement: https://alive2.llvm.org/ce/z/DfLwMV
- Another similar example also shows improvement: https://alive2.llvm.org/ce/z/hwJheB

I suspect the main optimization here comes from register reuse. I'm not sure how this would perform within a large function body, as it might complicate instruction selection.

For me, another important point is that *we can easily revert this forward if needed for other Passes. However, turning constants back into variables requires the dominance information.*

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


More information about the llvm-commits mailing list