llvm-project/llvm
Florian Hahn c74808b914 [PredicateInfo] Replace pointer comparisons with deterministic compares.
Currently there are a few pointer comparisons in ValueDFS_Compare, which
can cause non-deterministic ordering when materializing values. There
are 2 cases this patch fixes:

1. Order defs before uses used to compare pointers, which guarantees
   defs before uses, but causes non-deterministic ordering between 2
   uses or 2 defs, depending on the allocation order. By converting the
   pointers to booleans, we can circumvent that problem.

2. comparePHIRelated was comparing the basic block pointers of edges,
   which also results in a non-deterministic order and is also not
   really meaningful for ordering. By ordering by their destination DFS
   numbers we guarantee a deterministic order.

For the example below, we can end up with 2 different uselist orderings,
when running `opt -mem2reg -ipsccp` hundreds of times. Because the
non-determinism is caused by allocation ordering, we cannot reproduce it
with ipsccp alone.

    declare i32 @hoge() local_unnamed_addr #0

    define dso_local i32 @ham(i8* %arg, i8* %arg1) #0 {
    bb:
      %tmp = alloca i32
      %tmp2 = alloca i32, align 4
      br label %bb19

    bb4:                                              ; preds = %bb20
      br label %bb6

    bb6:                                              ; preds = %bb4
      %tmp7 = call i32 @hoge()
      store i32 %tmp7, i32* %tmp
      %tmp8 = load i32, i32* %tmp
      %tmp9 = icmp eq i32 %tmp8, 912730082
      %tmp10 = load i32, i32* %tmp
      br i1 %tmp9, label %bb11, label %bb16

    bb11:                                             ; preds = %bb6
      unreachable

    bb13:                                             ; preds = %bb20
      br label %bb14

    bb14:                                             ; preds = %bb13
      %tmp15 = load i32, i32* %tmp
      br label %bb16

    bb16:                                             ; preds = %bb14, %bb6
      %tmp17 = phi i32 [ %tmp10, %bb6 ], [ 0, %bb14 ]
      br label %bb19

    bb18:                                             ; preds = %bb20
      unreachable

    bb19:                                             ; preds = %bb16, %bb
      br label %bb20

    bb20:                                             ; preds = %bb19
      indirectbr i8* null, [label %bb4, label %bb13, label %bb18]
    }

Reviewers: davide, efriedma

Reviewed By: efriedma

Differential Revision: https://reviews.llvm.org/D64866

llvm-svn: 367049
2019-07-25 20:48:13 +00:00
..
benchmarks
bindings [IR/DIVar] Add the flag for params that have unmodified value 2019-06-26 11:19:26 +00:00
cmake [CMake] Add -z defs on Solaris 2019-07-23 16:27:34 +00:00
docs [Clang] New loop pragma vectorize_predicate 2019-07-25 07:33:13 +00:00
examples [ORC] Add deprecation warnings to ORCv1 layers and utilities. 2019-07-17 16:40:52 +00:00
include [DDG] DirectedGraph as a base class for various dependence graphs such 2019-07-25 18:23:22 +00:00
lib [PredicateInfo] Replace pointer comparisons with deterministic compares. 2019-07-25 20:48:13 +00:00
projects Revert "[libc++] Integrate the PSTL into libc++" 2019-07-19 18:52:46 +00:00
resources
runtimes
test [PredicateInfo] Replace pointer comparisons with deterministic compares. 2019-07-25 20:48:13 +00:00
tools Recommit "rL366894: [yaml2obj] - Allow custom fields for the SHT_UNDEF sections." 2019-07-25 10:19:23 +00:00
unittests [DDG] DirectedGraph as a base class for various dependence graphs such 2019-07-25 18:23:22 +00:00
utils [lit] Protect full test suite from FILECHECK_OPTS 2019-07-25 03:14:32 +00:00
.arcconfig
.clang-format
.clang-tidy
.gitattributes
.gitignore
CMakeLists.txt [cmake] Convert the NATIVE llvm build process to be project agnostic 2019-07-19 00:10:06 +00:00
CODE_OWNERS.TXT Update email address in CODE_OWNERS 2019-07-01 16:01:15 +00:00
CREDITS.TXT Update email address. 2019-07-17 07:02:02 +00:00
LICENSE.TXT
LLVMBuild.txt
README.txt
RELEASE_TESTERS.TXT
configure
llvm.spec.in

README.txt

The LLVM Compiler Infrastructure
================================

This directory and its subdirectories contain source code for LLVM,
a toolkit for the construction of highly optimized compilers,
optimizers, and runtime environments.

LLVM is open source software. You may freely distribute it under the terms of
the license agreement found in LICENSE.txt.

Please see the documentation provided in docs/ for further
assistance with LLVM, and in particular docs/GettingStarted.rst for getting
started with LLVM and docs/README.txt for an overview of LLVM's
documentation setup.

If you are writing a package for LLVM, see docs/Packaging.rst for our
suggestions.