[PATCH] D50558: [MustExecute] Fix algorithmic bug in isGuaranteedToExecute. PR38514

Max Kazantsev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 10 05:29:23 PDT 2018


mkazantsev created this revision.
mkazantsev added reviewers: reames, sanjoy, skatkov.

The description of `isGuaranteedToExecute` does not correspond to its implementation.
According to description, it should return `true` if an instruction is executed under the
assumption that its loop is *entered*. However there is a sophisticated alrogithm inside
that tries to prove that the instruction is executed if the loop is *exited*, which is not the
same thing for infinite loops. There is an attempt to protect from dealing with infinite loops
by prohibiting loops with exit blocks, however an infinite loop can have exit blocks.

As result of that, MustExecute can falsely consider some blocks that are never entered as
mustexec, and LICM can hoist dangerous instructions out of them basing on this fact.
This may introduce UB to programs which did not contain it initially.

This patch removes the problematic algorithm and replaced it with a one which tries to
prove what is required in description.


https://reviews.llvm.org/D50558

Files:
  include/llvm/Analysis/MustExecute.h
  lib/Analysis/MustExecute.cpp
  test/Analysis/MustExecute/infinite_loops.ll
  test/Analysis/MustExecute/loop-header.ll
  test/Transforms/LICM/infinite_loops.ll
  test/Transforms/LICM/preheader-safe.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D50558.160092.patch
Type: text/x-patch
Size: 12375 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180810/815b0f94/attachment.bin>


More information about the llvm-commits mailing list