[llvm] [ValueTracking] Fix "getOperand() out of range!" assertion crash (PR #87482)

Vedant Paranjape via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 10 01:18:19 PDT 2024


vedantparanjape-amd wrote:

> > > > Not sure this is really the right fix. If a function has a noundef attribute on the return value, then it cannot have a void return. This looks more like a context problem, in that we're dealing with two different functions during inlining.
> > > 
> > > 
> > > I suspected this, but the LangRef for noundef isn't really clear on this aspect: https://llvm.org/docs/LangRef.html. It's not mentioned anywhere that noundef attribute on the return value means it can't have a void return.
> > 
> > 
> > Yeah, this is not spelled out in LangRef, but it's verified here:
> > https://github.com/llvm/llvm-project/blob/4ae33c52f794dbd64924dd006570cdc409c297bc/llvm/lib/IR/Attributes.cpp#L2067-L2071
> 
> I see, this fix is just a workaround. noundef should not apply to the inlined function as such, as in atleast for ret instructions.
> 
> It is mostly happening because, somehow we are not DCE'ing ret void instructions, and before that we call simplifyinstruction
> 
> https://github.com/llvm/llvm-project/blob/313a33b9dff44dc2b0048484e54f9328d9a0d9db/llvm/lib/Transforms/Utils/CloneFunction.cpp#L854

@nikic okay I did some more analysis, so what is happening is. PruningFunctionCloner clones the basic blocks from function to be inlined into the caller function. While doing so, it handles terminator instructions like Switch/Branch, but it doesn't specially handle the Ret ones (https://github.com/llvm/llvm-project/blob/313a33b9dff44dc2b0048484e54f9328d9a0d9db/llvm/lib/Transforms/Utils/CloneFunction.cpp#L587), and clones it into the new function which has NoUndef attribute, so ideally this clone is illegal.

It becomes especially tricky as to how to handle it, given this return void statement has no successor.

https://github.com/llvm/llvm-project/pull/87482


More information about the llvm-commits mailing list