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

Stefanos Baziotis via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 16 17:21:48 PST 2019


baziotis marked an inline comment as done.
baziotis added inline comments.


================
Comment at: llvm/lib/Transforms/IPO/Attributor.cpp:2040
+  }
+};
+
----------------
baziotis wrote:
> jdoerfert wrote:
> > 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.
> Well, I was assuming initially that `%c = undef` can't appear anywhere, but I changed my mind because of the ref: https://llvm.org/docs/LangRef.html#undefined-values. However, it seems that one can't actually write this (only maybe LLVM from one pass to another ? I've no idea, it's obscure).
> First, no worries, ask if you need to find an API.
> I don't think we can do %some_name = undef though, the lang ref might need an update there.
:) I was searching for half an hour. Indeed, I had tried both `replaceAllUses` alone (which indeed replaced all uses but left the instruction as is), `deleteAfterManifest` (which did the previous thing + deleting the instruction - makes sense since `deleteAfterManifest` does pretty much `replaceAllUses` + `eraseFromParent`) but no way to do that. Can we somehow submit a patch for the LanguageRef ?

I just tried `changeToUnreachable` which eliminates the whole block :)




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

https://reviews.llvm.org/D71435





More information about the llvm-commits mailing list