[LLVMdev] Self-referential instruction from jump threading

Nick Lewycky nicholas at mxc.ca
Mon Oct 22 02:25:36 PDT 2012

Hal Finkel wrote:
> Hello,
> After investigating PR14133, I've discovered that jump threading can output self-referential instructions:
> %inc.us = add nsw i32 %inc.us, 1
> At least in the test case for that bug report, the relevant code is later deleted (perhaps it is unreachable), and so this does not cause a problem. Unfortunately, when vectorization is enabled, this instruction causes BBVectorize to hang. Should I make BBVectorize ignore this kind of thing, on the assumption that it occurs only in unreachable (or otherwise dead) code, or should this be fixed at the source (in jump threading in this case)?

The way to check whether it's valid is with the verifier. If jump 
threading were emitting that in a reachable block it would fail the 
verifier, in an unreachable block it would pass the verifier. Your pass 
gets to assume its input passes the verifier, and must produce output 
that does as well. That leads to the conclusion that if you see one of 
these in your input, then its parent block must be unreachable.


More information about the llvm-dev mailing list