Disclaimer: I'm not really familiar with the lowering code, and it looks pretty scary. If this doesn't make sense, I apologize in advance.
It seems that call to ReplaceAllUsesWith() when we're turning SHL -> AND is not really required and causes problems with the testcase below. It ends up producing an incorrect DAG, with a cycle in, so a topological order can't be assigned.
In particular this issue shows up if getConstant() gets an existing node in the graph rather than generating a new one, which is then incorrectly deleted causing the issue.
As an added note, In the test, {2, 127} can be changed to {4, 63} or {8, 31} and the issue remain.
%mul = mul i8 %trunc, 2 %and = and i8 %trunc, 127