This is an archive of the discontinued LLVM Phabricator instance.

[SelectionDAG] Fix a crash visiting `AND` nodes
ClosedPublic

Authored by davide on Oct 28 2016, 2:04 PM.

Details

Summary

When visiting we crash in t16: i64 = srl t40, Constant:i8<0> because we don't expect a shift-by-zero in visitAndLike.
I don't see a reason why this is invalid, and as discussed with Matt on IRC (which originally introduced this assertion) is probably fine to relax the condition a bit.

SelectionDAG has 11 nodes:
  t0: ch = EntryToken
  t2: i64 = Constant<0>
  t29: i32,ch = load<LD2[undef](align=8), sext from i16> t0, undef:i64, undef:i64
    t19: ch = TokenFactor t29:1, t0
        t40: i64 = sign_extend t29
      t16: i64 = srl t40, Constant:i8<0>
    t24: i64 = and t16, Constant:i64<65535>
  t20: ch = store<ST8[undef]> t19, t24, undef:i64, undef:i64

Diff Detail

Event Timeline

davide updated this revision to Diff 76244.Oct 28 2016, 2:04 PM
davide retitled this revision from to [SelectionDAG] Fix a crash visiting `AND` nodes.
davide updated this object.
davide added reviewers: arsenm, spatel, bogner, RKSimon.
davide added a subscriber: llvm-commits.
escha edited edge metadata.Oct 28 2016, 2:11 PM

Might it be better to just bail if ShiftBits is zero? This seems like a classic case of "trying to optimize a node that itself is going to disappear when it gets combine()'d", so maybe we should just not do this "optimization" if the shift is no shift at all.

Might it be better to just bail if ShiftBits is zero? This seems like a classic case of "trying to optimize a node that itself is going to disappear when it gets combine()'d", so maybe we should just not do this "optimization" if the shift is no shift at all.

I agree. Performing this transformation won't make it any easier to get rid of the zero shift (and if it does, it shouldn't).

Might it be better to just bail if ShiftBits is zero? This seems like a classic case of "trying to optimize a node that itself is going to disappear when it gets combine()'d", so maybe we should just not do this "optimization" if the shift is no shift at all.

Sounds reasonable.

spatel added inline comments.Oct 28 2016, 2:23 PM
test/CodeGen/X86/visitand-shift.ll
1 ↗(On Diff #76244)

We shouldn't need the "-O0" here?
Also, please give the file and/or the test a meaningful name - PR30813?

davide updated this revision to Diff 76247.Oct 28 2016, 2:45 PM
davide updated this revision to Diff 76248.
davide edited edge metadata.

Update correct revision.

test/CodeGen/X86/visitand-shift.ll
1 ↗(On Diff #76244)

Renamed the file. It doesn't crash without -O0.

hfinkel accepted this revision.Oct 28 2016, 2:50 PM
hfinkel added a reviewer: hfinkel.
hfinkel added inline comments.
lib/CodeGen/SelectionDAG/DAGCombiner.cpp
3053

To micro-optimize, I'd move this to before we count bits in the AndMask and get the integer VT. Otherwise, LGTM.

This revision is now accepted and ready to land.Oct 28 2016, 2:50 PM
This revision was automatically updated to reflect the committed changes.