This patch intends to enable jump threading with a method whose return type is std::pair<int, bool> or std::pair<bool, int>
For example, jump threading does not work for the if statement in func.
std::pair<int, bool> callee(int v) { int a = dummy(v); if (a) return std::make_pair(dummy(v), true); else return std::make_pair(v, v < 0); } int func(int v) { std::pair<int, bool> rc = callee(v); if (rc.second) { // do something }
SROA executed before the method inlining replaces std::pair by i64 without splitting in both callee and func since at this point no access to the individual fields is seen to SROA.
After inlining, jump threading fails to identify that the incoming value is a constant due to additional instructions (like or, and, trunc).
This series of patch add two patterns in InstructionSimplify to fold extraction of members of std::pair. To help jump threading, actually we need to optimize the code sequence spanning multiple BBs.
These patches does not handle phi by itself, but these additional patterns help NewGVN pass, which calls instsimplify to check opportunities for simplifying instructions over phi, apply phi-of-ops optimization to result in successful jump threading.
Later, in the CFG simplification pass, the similar code modification happens. But it is too late to help jump threading.
This series of patches replaces my old patch D44626 which do similar optimization in InstCombine as suggested by reviewers.
This first patch in the series handles code sequences that merges two values using shl and or and then extracts one value using lshr.
Alive proof for the shift case: https://rise4fun.com/Alive/epNB, mask Y case: https://rise4fun.com/Alive/vgH
I think this shouldn't talk about C++ here. Just talk about IR.