Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RISCV] Convert more constant splats in tests to splat shorthand. NFC #87616

Merged
merged 3 commits into from
Apr 9, 2024

Conversation

lukel97
Copy link
Contributor

@lukel97 lukel97 commented Apr 4, 2024

A handy shorthand for specifying the shufflevector(insertelement(poison, foo, 0), poison, zeroinitializer) splat pattern was introduced in #74620.

Some of the RISC-V tests were converted over to use this new form in dbb65dd, this patch handles the rest which didn't have any codegen diffs.

This not only converts some constant expressions to the new form, but also instruction sequences that weren't previously constant expressions to constant expressions as well. In some cases this affects codegen, but these have been omitted here and will be handled in a separate PR to show the diff better.

Script used for reference

#!/usr/bin/perl
use warnings;
use strict;

open my $fh, '<', $ARGV[0] or die $!;
my $data = do { local $/; <$fh> };

$data =~ s/shufflevector\s*\(<.+>\s*insertelement\s*\(<.+>\s*(?:poison|undef),\s+(.+),\s+i\d+\s0\),\s+<.+>\s+(?:poison|undef),\s<.+>\s+zeroinitializer\)/splat ($1)/g;

my @funcs = split('(define)', $data);

foreach my $func (@funcs) {
    while ($func =~ /\n\s+%([\w\.]+)\s=\sinsertelement\s<.+x\s(\w+)>\s(?:poison|undef),\s\2\s([\.\-\w]+),\si\d+\s0\n\s+%([\w\.]+)\s=\sshufflevector\s<.+>\s%\1,\s<.+>\s(?:poison|undef),\s<.+>\szeroinitializer/g) {
	my $type = $2;
	my $val = $3;
	my $splat_var = $4;

	$func =~ s/\n\s+%([\w\.]+)\s=\sinsertelement\s<.+x\s(\w+)>\s(?:poison|undef),\s\2\s([\.\-\w]+),\si\d+\s0\n\s+%([\w\.]+)\s=\sshufflevector\s<.+>\s%\1,\s<.+>\s(?:poison|undef),\s<.+>\szeroinitializer//;

	$func =~ s/%$splat_var/splat ($type $val)/g;
    }
}

open my $out, '>', $ARGV[0] or die $!;

print $out @funcs;

…. NFC

A handy shorthand for specifying the shufflevector(insertelement(poison, foo, 0), poison, zeroinitializer) splat pattern was introduced in llvm#74620.

Some of the RISC-V tests were converted over to use this new form in dbb65dd, this patch handles the rest.

This converts some constant expressions to the new form, but it also converts instruction sequences that weren't previously constant expressions to constant expressions as well. In some cases this causes some minor code motion in the test output, but it's not significant to the test itself. E.g. see llvm/test/CodeGen/RISCV/rvv/fixed-vectors-masked-{gather,scatter}.ll
Copy link
Contributor

@wangpc-pp wangpc-pp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!
(Did you convert these tests manually or via some scripts?)

@lukel97
Copy link
Contributor Author

lukel97 commented Apr 4, 2024

LGTM, thanks!

(Did you convert these tests manually or via some scripts?)

I wrote a Perl script, it should be attached it in the PR description. I really don't know Perl at all though, I'm sure it's terrible!

@wangpc-pp
Copy link
Contributor

LGTM, thanks!
(Did you convert these tests manually or via some scripts?)

I wrote a Perl script, it should be attached it in the PR description. I really don't know Perl at all though, I'm sure it's terrible!

Yeah, I see it now (the script is collapsed so I didn't notice it).

@lukel97 lukel97 changed the title [RISCV] Convert remaining constant splats in tests to splat shorthand. NFC [RISCV] Convert more constant splats in tests to splat shorthand. NFC Apr 8, 2024
Copy link
Collaborator

@topperc topperc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM assuming no codegen changes are hidden in here. I see you split those out.

@lukel97 lukel97 merged commit d8d131d into llvm:main Apr 9, 2024
3 of 4 checks passed
lukel97 added a commit to lukel97/llvm-project that referenced this pull request Apr 9, 2024
…hand. NFC

This follows on from llvm#87616, but includes the tests with codegen differences. These are presumably due to the fact that the splat is now a constant expression. They don't seem to affect anything that we were specifically testing for.
lukel97 added a commit that referenced this pull request Apr 9, 2024
…hand. NFC (#88099)

This follows on from #87616, but includes the tests with codegen
differences. These are presumably due to the fact that the splat is now
a constant expression. They don't seem to affect anything that we were
specifically testing for.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants