[PATCH] D71435: [WIP] [Attributor] Function level undefined behavior attribute

Johannes Doerfert via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 12 15:04:48 PST 2019


jdoerfert added a comment.

In D71435#1782577 <https://reviews.llvm.org/D71435#1782577>, @lebedev.ri wrote:

> I'm a little dubious on the use-case of such an attribute, perhaps you can add that into patch's description.


Let me answer this one as I proposed this project.

The Attributor uses liveness extensively to improve results. I mean, basically all results are "conditional" in the sense SCCP is "conditional".
Liveness in SCCP, and so far in the Attributor, is mostly derived by not following assumed dead branches. Having the ability to reason about UB will allow us to augment this.

Take the following derived example (https://godbolt.org/z/ZcGWiC)

  extern int Condition;
  
  int extern_fn(void);
  
  static void internal_fn(int *a) {
    if (Condition) {
      *a = 1;
      extern_fn();
    }
  }
  
  void entry() {
    internal_fn(0);
  }

While we remove the store to the nullptr and add a trap eventually, we keep the conditional and we introduce a trap. Both are actually harmful for optimization purposes.
I know this is constructed example but we see a lot of known UB (not necessarily load related) after inlining and constant prop which would be very valuable to prune infeasible paths.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D71435/new/

https://reviews.llvm.org/D71435





More information about the llvm-commits mailing list