llvm-project/llvm/lib
David Stenberg 23bba56fce [CodeGen] Make block removal order deterministic in CodeGenPrepare
Summary:
Replace use of a SmallPtrSet with a SmallSetVector to make the worklist
iteration order deterministic. This is done as the order the blocks are
removed may affect whether or not PHI nodes in successor blocks are
removed.

For example, consider the following case where %bb1 and %bb2 are
removed:

    bb1:
      br i1 undef, label %bb3, label %bb4
    bb2:
      br i1 undef, label %bb4, label %bb3
    bb3:
      pv1 = phi type [ undef, %bb1 ], [ undef, %bb2], [ v0, %other ]
      br label %bb4
    bb4:
      pv2 = phi type [ undef, %bb1 ], [ undef, %bb2 ],
                     [ pv1, %bb3 ], [ v0, %other ]

If %bb2 is removed before %bb1, the incoming values from %bb1 and %bb2
to pv1 will be removed before %bb1 is removed as a predecessor to %bb4.
The pv1 node will thus be optimized out (to v0) at the time %bb1 is
removed as a predecessor to %bb4, leaving the blocks as following when
the incoming value from %bb1 has been removed:

    bb3: ; pv1 optimized out, incoming value to pv2 is v0
      br label %bb4
    bb4:
      pv2 = phi type [ v0, %bb3 ], [ v0, %other ]

The pv2 PHI node will be optimized away by removePredecessor() as all
incoming values are identical.

In case %bb2 is removed after %bb1, pv1 will not be optimized out at the
time %bb2 is removed as a predecessor to %bb4, leaving the blocks as
following when the incoming value from %bb2 to pv2 has been removed:

    bb3:
      pv1 = phi type [ undef, %bb2 ], [ v0, %other ]
      br label %bb4
    bb4:
      pv2 = phi type [ pv1, %bb3 ], [ v0, %other ]

The pv2 PHI node will thus not be removed in this case, ultimately
leading to the following output

    bb3: ; pv1 optimized out, incoming value to pv2 is v0
      br label %bb4
    bb4:
      pv2 = phi type [ v0, %bb3 ], [ v0, %other ]

I have not looked into changing DeleteDeadBlock() so that the redundant
PHI nodes are removed.

I have not added a test case, as I was not able to create a particularly
small and (not messy) reproducer. This is likely due to SmallPtrSet
behaving deterministically when in small mode.

Reviewers: void, dexonsmith, spatel, skatkov, fhahn, bkramer, nhaehnle

Reviewed By: fhahn

Subscribers: mgrang, llvm-commits

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

llvm-svn: 336109
2018-07-02 14:23:48 +00:00
..
Analysis Implement strip.invariant.group 2018-07-02 04:49:30 +00:00
AsmParser [ThinLTO] Parse module summary index from assembly 2018-06-26 13:56:49 +00:00
BinaryFormat [WebAssembly] Move toString helpers to BinaryFormat 2018-05-14 22:42:07 +00:00
Bitcode [ThinLTO] Parse module summary index from assembly 2018-06-26 13:56:49 +00:00
CodeGen [CodeGen] Make block removal order deterministic in CodeGenPrepare 2018-07-02 14:23:48 +00:00
DebugInfo [CodeView] Correctly compute the name of S_PROCREF symbols. 2018-06-29 22:19:02 +00:00
Demangle Fix spelling mistakes in comments. NFCI. 2018-06-26 14:06:23 +00:00
ExecutionEngine [ORC] Don't call isa<> on a null value. 2018-06-26 22:43:01 +00:00
FuzzMutate [llvm-opt-fuzzer] Add irce to the fuzzing options 2018-03-20 11:32:13 +00:00
Fuzzer
IR Implement strip.invariant.group 2018-07-02 04:49:30 +00:00
IRReader LLParser: add an argument for overriding data layout and do not check alloca addr space 2018-01-30 22:32:39 +00:00
LTO LTO: Keep file handles open for memory mapped files. 2018-06-13 18:03:14 +00:00
LineEditor
Linker IRMover: Account for matching types present across modules 2018-06-20 16:50:56 +00:00
MC Add an entry for rodata constant merge sections to the default 2018-07-02 00:16:39 +00:00
Object [llvm-readobj] Add experimental support for SHT_RELR sections 2018-06-28 21:07:34 +00:00
ObjectYAML [llvm-readobj] Add experimental support for SHT_RELR sections 2018-06-28 21:07:34 +00:00
Option Re-revert "[Option] Fix PR37006 prefix choice in findNearest" 2018-05-19 16:21:01 +00:00
Passes [UnrollAndJam] New Unroll and Jam pass 2018-07-01 12:47:30 +00:00
ProfileData [NFC] Change sample profile format enum name SPF_Raw_Binary to SPF_Binary. 2018-06-12 05:53:49 +00:00
Support [ARM][AArch64] Armv8.4-A Enablement 2018-06-29 08:43:19 +00:00
TableGen [TableGen] Use WithColor for printing errors/warnings 2018-06-23 16:48:03 +00:00
Target [X86] Use addAliasForDirective to support the .word directive (reland) 2018-07-02 13:49:52 +00:00
Testing [LLVMTestingSupport] Add explicit linkage to LLVMSupport 2018-04-08 06:49:17 +00:00
ToolDrivers [COFF] Improve correctness of def parsing for GNU features 2018-05-09 09:21:53 +00:00
Transforms [SLPVectorizer] Remove nullptr early-outs from Instruction::ShuffleVector getEntryCost 2018-07-02 13:41:29 +00:00
WindowsManifest Convert line endings of lib/WindowsManifest/CMakeLists.txt to unix. 2018-04-07 04:28:08 +00:00
XRay [XRay] clarify error messages when parsing broken traces 2018-01-30 13:41:34 +00:00
CMakeLists.txt
LLVMBuild.txt