| Issue |
169919
|
| Summary |
Missed optimization for switches using getelementptr
|
| Labels |
llvm:optimizations,
missed-optimization
|
| Assignees |
|
| Reporter |
OutOfCache
|
This example is a simplified version from a case we encountered:
https://godbolt.org/z/Pn3roafKe
We can optimize the switch away by replacing the getelementptrs with the `merge.gep`s in the merge blocks (since https://github.com/llvm/llvm-project/pull/156477 and https://github.com/llvm/llvm-project/pull/158242):
https://godbolt.org/z/a73ThKvxc
InstCombinePHI can do just that with `foldPHIArgGEPIntoPHI` https://github.com/llvm/llvm-project/blob/06c8ee61ab80305be88380e6aa2f1b2fe32f859d/llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp#L535.
However, in this case the transform fails because:
1. There are multiple users
2. The offsets are constant
Both cases prevent the transform due to pessimization. Aborting on constant indices ensures phis into structs do not introduce invalid getelementptrs. Maybe we could relax this restriction on non-struct phis but the multiple users restriction still blocks optimizing our case.
What is the best way to optimize this case? Can we extend `foldPHIArgGEPIntoPHi` in InstCombine or should we implement this in SimplifyCFG?
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs