This is an archive of the discontinued LLVM Phabricator instance.

[InstCombine] replace undef in vector constant for safe shift transform (PR45447)
ClosedPublic

Authored by spatel on Apr 8 2020, 9:21 AM.

Details

Summary

As noted in PR45447, we have a vector-constant-with-undef-element transform bug:
https://bugs.llvm.org/show_bug.cgi?id=45447

We replace undefs with a safe constant (0 or -1) based on the (non-)negative
predicate constraint.

So this is correct:
http://volta.cs.utah.edu:8080/z/WZE36H
...but this is not:
http://volta.cs.utah.edu:8080/z/boj8gJ

Previously, we were relying on getSafeVectorConstantForBinop() in the related fold (D76800).
But that's making an assumption about what qualifies as "safe", and that assumption may
not always hold.

Diff Detail

Event Timeline

spatel created this revision.Apr 8 2020, 9:21 AM
lebedev.ri accepted this revision.Apr 8 2020, 9:28 AM

This LG.

This revision is now accepted and ready to land.Apr 8 2020, 9:28 AM
spatel planned changes to this revision.Apr 8 2020, 12:49 PM

Thinking about this again...assuming that we know what getSafeVectorConstantForBinop() is going to return is dirty. Let's just replace undefs with the values we want.

spatel updated this revision to Diff 256093.Apr 8 2020, 12:51 PM

Patch updated:
Use replaceUndefsWith() directly with 0/-1 constants, so we're not implicitly assuming the behavior of the APIs.

This revision is now accepted and ready to land.Apr 8 2020, 12:51 PM
spatel requested review of this revision.Apr 8 2020, 12:53 PM
lebedev.ri accepted this revision.Apr 8 2020, 1:53 PM

I suspect there are other cases like this (where we used getSafeVectorConstantForBinop()).

This revision is now accepted and ready to land.Apr 8 2020, 1:53 PM
spatel added a comment.Apr 9 2020, 5:14 AM

I suspect there are other cases like this (where we used getSafeVectorConstantForBinop()).

I did a quick check of the remaining (3) uses, and they look ok to me. Those are shuffle+binop transforms and are not gated by a constraint on the constant values (other than we don't want to create extra UB/poison via re-ordering).

spatel edited the summary of this revision. (Show Details)Apr 9 2020, 5:20 AM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptApr 9 2020, 5:23 AM