This is an archive of the discontinued LLVM Phabricator instance.

[RISCVInsertVSETVLI] Remove an unsound optimization
ClosedPublic

Authored by reames on Aug 5 2022, 8:19 AM.

Details

Summary

This fixes a bug reported privately by @craig.topper. Here's an example which illustrates the problem:

vsetivli a1, a0, e32, m1, ta, mu # both DefInfo and PrevInfo
vsetivli a2, a1, e32, m4, ta, mu

With the unsound result being:

vsetivli a1, a0, e32, m1, ta, mu 
vsetivli a2, a0, e32, m4, ta, mu

Consider the case where this is running on a machine with VLEN=512,. For this case, the VLMAXs are 16 and 64 respectively.

Consider for a0 = 33. The correct result is: a1 = 16, and a2 = 16

After the unsound optimization: a1 = 16 and a2 = 33

This particular example used VLMAXs which differed by more than a power of two. With a difference of only one power of two, there's another form of this bug which involves the AVL < 2 x VLMAX special case, but that ones more complicated to construct as many examples turn out accidentally sound.

This patch takes the approach of simply removing the unsound optimization, but there are multiple sound sub-cases of it. I plan to return to at least a couple of them, but figured it was cleaner to remove the unsound optimization (for ease of backporting), and then review the new optimizations on their own.

Diff Detail

Event Timeline

reames created this revision.Aug 5 2022, 8:19 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 5 2022, 8:19 AM
reames requested review of this revision.Aug 5 2022, 8:19 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 5 2022, 8:19 AM
This revision is now accepted and ready to land.Aug 5 2022, 12:06 PM
This revision was landed with ongoing or failed builds.Aug 5 2022, 12:13 PM
This revision was automatically updated to reflect the committed changes.