[instcombine] propagate freeze through single use poison producing flag instruction
authorPhilip Reames <listmail@philipreames.com>
Tue, 12 Oct 2021 20:45:11 +0000 (13:45 -0700)
committerPhilip Reames <listmail@philipreames.com>
Tue, 12 Oct 2021 20:52:41 +0000 (13:52 -0700)
commit6f348394079f8baa8f33bf68a50457c108e2305f
tree6ff251f5bafa4f5d93cc88ace076d5b300bdff52
parent884d290427e54eaf4b1123389c7b2665f86df7e3
[instcombine] propagate freeze through single use poison producing flag instruction

If we have an instruction which produces poison only when flags are specified on the instruction, then we know that freezing the operands and dropping flags is equivalent to freezing the result. If we know those flags don't result in any undefined behavior being executed, then there's no point in preserving the flags as we gain no knowledge by having them.

This patch extends the existing propagation logic which sinks freeze to single potential non-poison operands to allow dropping of flags when we know the freeze is the sole use of the instruction with poison flags.

The main value is that we tend to sink freezes towards the phi in IV cycles where the incoming value to the phi is the freeze of an IV increment. This will in turn (in a future patch), let us fold the freeze through the phi into the loop preheader. Motivated by eliminating need for CanonicalizeFreezeInLoops for the clearly profitable cases from onephi.ll test case in the test directory.

Differential Revision: https://reviews.llvm.org/D111675
llvm/include/llvm/Analysis/ValueTracking.h
llvm/lib/Analysis/ValueTracking.cpp
llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
llvm/test/Transforms/InstCombine/freeze.ll