[PATCH] D127960: [InstCombine] Push freeze through recurrence phi

Nikita Popov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 16 06:07:15 PDT 2022


nikic created this revision.
nikic added reviewers: fhahn, nlopes, aqjune, reames, spatel.
Herald added a subscriber: hiraditya.
Herald added a project: All.
nikic requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

We really want to push freezes through recurrence phis, so that we freeze only the start value, rather than the IV value on every iteration. foldOpIntoPhi() already handles this for the case where the transfer function doesn't produce poison, e.g. `%iv.next = add %iv, 1`. However, this does not work if nowrap flags are present, e.g. the very common `%iv.next = add nuw %iv, 1` case.

This patch adds a fold that pushes freeze instructions to the start value by checking whether all backedge values will be non-poison after poison generating flags have been dropped. This allows pushing freezes out of loops in most cases. I suspect that this also obsoletes the CanonicalizeFreezeInLoops pass, and we can probably drop it.

Fixes https://github.com/llvm/llvm-project/issues/56048.


https://reviews.llvm.org/D127960

Files:
  llvm/lib/Transforms/InstCombine/InstCombineInternal.h
  llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
  llvm/test/Transforms/InstCombine/freeze.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D127960.437521.patch
Type: text/x-patch
Size: 6580 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220616/f1e6e2d8/attachment.bin>


More information about the llvm-commits mailing list