This is an archive of the discontinued LLVM Phabricator instance.

[SROA] Create additional vector type candidates based on store and load slices
ClosedPublic

Authored by A-Wadhwani on Aug 17 2022, 8:18 PM.

Details

Summary

This patch adds additional vector types to be considered when doing promotion in SROA, based on the types of the store and load slices. This provides more promotion opportunities, by potentially using an optimal "intermediate" vector type.

For example, the following code would currently not be promoted to a vector, since __m128i is a <2 x i64> vector.

#include <xmmintrin.h>

__m128i packfoo0(int a, int b, int c, int d) {
  int r[4] = {a, b, c, d};
  __m128i rm;
  std::memcpy(&rm, r, sizeof(rm));
  return rm;
}
packfoo0(int, int, int, int):
        mov     dword ptr [rsp - 24], edi
        mov     dword ptr [rsp - 20], esi
        mov     dword ptr [rsp - 16], edx
        mov     dword ptr [rsp - 12], ecx
        movaps  xmm0, xmmword ptr [rsp - 24]
        ret

By also considering the types of the elements, we could find that the <4 x i32> type would be valid for promotion, hence removing the memory accesses for this function. In other words, we can explore other new vector types, with the same size but different element types based on the load and store instructions from the Slices, which can provide us more promotion opportunities.

Additionally, the step for removing duplicate elements from the CandidateTys vector was not using an equality comparator, which has been fixed.

Diff Detail

Event Timeline

A-Wadhwani created this revision.Aug 17 2022, 8:18 PM
A-Wadhwani created this object with visibility "A-Wadhwani (Aryan Wadhwani)".
Herald added a project: Restricted Project. · View Herald TranscriptAug 17 2022, 8:18 PM
A-Wadhwani requested review of this revision.Aug 17 2022, 8:18 PM
A-Wadhwani changed the edit policy from "All Users" to "A-Wadhwani (Aryan Wadhwani)".
A-Wadhwani edited the summary of this revision. (Show Details)Aug 17 2022, 8:23 PM
A-Wadhwani changed the visibility from "A-Wadhwani (Aryan Wadhwani)" to "Public (No Login Required)".
A-Wadhwani changed the edit policy from "A-Wadhwani (Aryan Wadhwani)" to "All Users".
A-Wadhwani added subscribers: MatzeB, wenlei, zhuhan0.

Fixed issues with clang-format

This looks good to me. I'd propose to wait a few more days for people with more experience in SROA and vector IR to chime in, if noone complains we can land this.

Pinging for a review on this.

MatzeB accepted this revision.Sep 1 2022, 2:13 PM

LGTM with no other concerns raised.

I assume I have to land this patch for you, what exact name and E-Mail address should I attribute it to?

This revision is now accepted and ready to land.Sep 1 2022, 2:13 PM

Thank you! My name would be A-Wadhwani and email is aryan.w2203@gmail.com.

dyung added a subscriber: dyung.Sep 16 2022, 10:00 PM

Hi @A-Wadhwani, this change hit an assertion failure in one of our internal tests. I have put the details in GHI #57796, can you take a look?

dyung added a comment.EditedSep 19 2022, 6:13 AM

This change also seems to be causing a miscompile in another one of our internal tests and I have filed that as GHI #57821. @A-Wadhwani, can you take a look into that issue as well?

Hey @dyung, I think I have an idea as to what's causing the first issue, and I'll try to figure out what's up with the second issue. Thanks for bringing these up!

Hey @dyung, I think I have an idea as to what's causing the first issue, and I'll try to figure out what's up with the second issue. Thanks for bringing these up!

Hi @A-Wadhwani, are you actively looking into the issues I mentioned? If so, any ETA? If you are not currently looking into them, or need more time to investigate, I'm inclined to revert the change as it has been a few days since they were reported with no updates and I am inclined to revert your change because it has some known issues.

if you can show with a repro that this patch causes an issue then yes feel free to revert

There was some bugfix in D134032 but if that was unrelated and this is still broken with the repros in your github issues, then by all means revert. We can always re-land when things are fixed.

Hi! I think the bugfix in that patch might have referred to a different issue.

I think for now, the best thing would be to just revert this patch, and I can come back with a fix for it soon.

I can confirm that the issues I bisected to this commit in GHI #57796 and #57821 are still present in commit 465ec4e0b48c005f5d5de8adee0c33469a7b9862, so I will be reverting the change.