The problem (as I understand it) is the DAG eventually ends up representing
a necessary EFLAGS copy. But we deliberately do not perform EFLAGS copies
because they are impossible on x86 (see InstrEmitter.cpp:171 or thereabouts),
so we end up using whatever happens to be in EFLAGS at the time of the branch.
This problem does not end up affecting compares/overflow checks because
they are schedule-independent, so we can easily move (or copy) the
instruction to wherever is convenient.
The workaround I came up with was to disable a simplification that may lead
to such a copy occurring, specifically the one that eliminates SETCC nodes, if
they refer to a CopyFromReg which may not be scheduled right before the branch,
in the hope that the SETCC will be scheduled in the right place. This turned
out to be not so great; a number of tests now fail because of extra copies.
One other idea I had was a peephole MI pass that removes SETCC instructions
if safe to do so. Does that sound like a good idea?
There may be a much better way of solving this. I'm not a backend expert;
this is what I have gleaned after staring at selection DAGs for far too
long.