[DFAJumpThreading] Relax analysis to handle unpredictable initial values
authorAlex Zhikhartsev <alex.zhi@huawei.com>
Wed, 25 May 2022 23:10:57 +0000 (19:10 -0400)
committerAlex Zhikhartsev <alex.zhi@huawei.com>
Thu, 26 May 2022 15:29:54 +0000 (11:29 -0400)
commit8b0d7634743965948234b666c77393d4dd8535d7
tree6160f0ae673b2c772fa4f5be29252b1cd6effcb6
parent9c66ed9b73170519a87310444d4624b519c2983b
[DFAJumpThreading] Relax analysis to handle unpredictable initial values

Responding to a feature request from the Rust community:

https://github.com/rust-lang/rust/issues/80630

    void foo(X) {
      for (...)
switch (X)
  case A
    X = B
  case B
    X = C
    }

Even though the initial switch value is non-constant, the switch
statement can still be threaded: the initial value will hit the switch
statement but the rest of the state changes will proceed by jumping
unconditionally.

The early predictability check is relaxed to allow unpredictable values
anywhere, but later, after the paths through the switch statement have
been enumerated, no non-constant state values are allowed along the
paths. Any state value not along a path will be an initial switch value,
which can be safely ignored.

Differential Revision: https://reviews.llvm.org/D124394
llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp
llvm/test/Transforms/DFAJumpThreading/dfa-jump-threading-analysis.ll
llvm/test/Transforms/DFAJumpThreading/negative.ll