Due to a combination of canonicalization of induction vars and subsequent inlining/simplification, we are sometimes left with a PHINode which only uses a load and bitcasts, and whose only user is also a bitcast. If the bitcasts are noop and tautological when concatenated, we can instead fold the desired type through the PHI into the load and get rid of some cast clutter.
Details
Diff Detail
- Repository
- rL LLVM
Event Timeline
The idea here makes total sense to me, but I don't think this is the right way to do it.
I think you should be combining the PHI or cast, not the load. The combine should be to hoist a cast of a PHI around the PHI if all of the PHI inputs are casts and loads. You might also need to enqueue the loads in the combiner afterward so we revisit them and recognize that we can fold the cast into the load.
I adopted Chandler's suggestion of combining the PHI instead of the Load and updated the patch accordingly. I also added a missing RUN line to the test case.
The idea here is to detect a PHI whose only user is a Noop CastInst and then fold the cast back through the phi if the phi only depends on loads and matching casts. This produces a new cast for an incoming load (which should be folded into the loop later on), and skips incoming casts.