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

Johannes Doerfert via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 16 17:03:12 PST 2019


jdoerfert added inline comments.


================
Comment at: llvm/lib/Transforms/IPO/Attributor.cpp:2040
+  }
+};
+
----------------
baziotis wrote:
> jdoerfert wrote:
> > baziotis wrote:
> > > jdoerfert wrote:
> > > > Let's also add a manifest method to replace the loads that are still considered UB with an undef (for now). That should allow us to test this.
> > > The whole instruction? Like replace `%a = load i32, i32* null` with `undef`. I don't think this can happen. Maybe I misunderstood and you meant replace it with this: `%a = load i32, i32* undef` (i.e. replace the pointer operand value).
> > Your first interpretation was what I meant. Replace the load (instruction) with undef. We actually want to be more aggressive but we will need that step either way.
> Sorry but I couldn't find a way to do that. I've seen in the language reference that one can do this: `%some_name = undef` and so I guess this is what we want, but I couldn't produce it. The closest thing I found is `deleteAfterManifest` which replaces _its uses_ with `undef` but will also delete the instruction. I guess we actually need the instruction (or, its replaced counterpart) so that the info of undefined behavior stays.
First, no worries, ask if you need to find an API. The code below was obviously not tested but should do what I described earlier:

`I.replaceAllUsesWith(UndefValue::get(I.getType()))`

You can also use `deleteAfterManifest`, actually you probably should use that instead. Or we directly go one step further and use `llvm::changeToUnreachable` (as AAIsDead does).

P.S.
I don't think we can do `%some_name = undef` though, the lang ref might need an update there.


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

https://reviews.llvm.org/D71435





More information about the llvm-commits mailing list