This is an archive of the discontinued LLVM Phabricator instance.

Remove assert from ShuffleVectorInst
ClosedPublic

Authored by samparker on Jun 11 2020, 1:03 AM.

Details

Summary

Which triggers on valid, but not useful, IR such as a undef mask.

Bugzilla: https://bugs.llvm.org/show_bug.cgi?id=46276

Diff Detail

Event Timeline

samparker created this revision.Jun 11 2020, 1:03 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 11 2020, 1:03 AM
Herald added a subscriber: hiraditya. · View Herald Transcript
uabelho resigned from this revision.Jun 11 2020, 1:20 AM

Thanks for the patch so quickly!
I really have no idea if the assert actually makes sense or not though, so it's best if @spatel can have an opinion.

Was the failure only a fuzzer problem?
Ideally, callers shouldn't be wasting their time on analysis of degenerate code, so that assert might have actually been useful for real code.
Also, if this did happen in real code, we probably don't want to claim that this shuffle uses a source value if the shuffle doesn't actually exist (see inline comment).

llvm/lib/IR/Instructions.cpp
2056

I think it would be better to change to:

// Allow for degenerate case: completely undef mask means neither source is used.
return UsesLHS || UsesRHS;
llvm/test/CodeGen/X86/cgp_shuffle_crash.ll
1 ↗(On Diff #270051)

I prefer a more direct test of CGP using "opt -codegenprepare -S".
That test should live in this directory:
llvm/test/Transforms/CodeGenPrepare/X86

Also, the test can be reduced to a single block (not sure if this is minimal):

define <2 x i8> @autogen_SD20565(i32 %x) {
  %Shuf = shufflevector <2 x i8> zeroinitializer, <2 x i8> zeroinitializer, <2 x i32> undef
  %Cmp = icmp slt i32 480483, %x
  %B = mul <2 x i8> %Shuf, %Shuf
  %S = select i1 %Cmp, <2 x i8> %B, <2 x i8> zeroinitializer
  ret <2 x i8> %Shuf
}
samparker marked an inline comment as done.Jun 11 2020, 5:18 AM

Was the failure only a fuzzer problem?

Not sure, but either it seems harsh to assert of technically legal IR.

Ideally, callers shouldn't be wasting their time on analysis of degenerate code, so that assert might have actually been useful for real code.

I'll have a look into the callsites to see if it's easier enough to skip on undef masks.

llvm/lib/IR/Instructions.cpp
2056

Looks good.

samparker updated this revision to Diff 270112.Jun 11 2020, 5:58 AM
  • Changed return value and added comment.
  • Added a few internal UndefValue where possible.
  • Moved test.
spatel accepted this revision.Jun 11 2020, 6:17 AM

LGTM

llvm/lib/IR/Instructions.cpp
2056

Formatting: 80-column.

llvm/test/Transforms/CodeGenPrepare/X86/cgp_shuffle_crash.ll
14

bugpoint tends to produce tests like this with undef/unused values, and then those tests wiggle or become worthless when unrelated improvements are made. For that reason, I still prefer my more-defined version of the test. :)

This revision is now accepted and ready to land.Jun 11 2020, 6:17 AM
samparker marked an inline comment as done.Jun 11 2020, 6:44 AM
samparker added inline comments.
llvm/test/Transforms/CodeGenPrepare/X86/cgp_shuffle_crash.ll
14

Ah, sorry, will do.

This revision was automatically updated to reflect the committed changes.

Was the failure only a fuzzer problem?

My case showed up when generating llc input with llvm-stress.