Page MenuHomePhabricator

[RISCV] Add a test showing incorrect codegen
ClosedPublic

Authored by frasercrmck on Jan 20 2021, 12:05 AM.

Details

Summary

This patch adds a test which shows how the compiler incorrectly sets the
size and alignment of a stack object used to indirectly pass vector
types to functions.

In the particular example, the test passes a <4 x i8> vector type to a
function and creates a stack object of size and alignment equal to 4
bytes. However, the code generated to set up that parameter has been
scalarized and stores each element as individual XLEN-sized values. Thus
on RV32 this stores 16 bytes and on RV64 32 bytes, both of which clobber
the stack. Similarly, the alignment is set up as the alignment
of the vector type, which is not necessarily the natural alignment of XLEN.

Diff Detail

Event Timeline

frasercrmck created this revision.Jan 20 2021, 12:05 AM
frasercrmck requested review of this revision.Jan 20 2021, 12:05 AM
Herald added a project: Restricted Project. · View Herald TranscriptJan 20 2021, 12:05 AM

I posted something about this bug late last year but haven't found the time to progress with it. So I thought I'd at least put up a test case so it's tracked.

Are we moving away from update_llc_test_checks.py for vector tests?

Are we moving away from update_llc_test_checks.py for vector tests?

Please no, update_llc_test_checks.py is one of the best things to have happened to LLVM tests, both as an upstream developer and for significant downstream forks.

I suspect it wasn't used because this is an IR->MIR test; there's utils/update_mir_test_checks.py for that (works with both IR and MIR input).

I suspect it wasn't used because this is an IR->MIR test; there's utils/update_mir_test_checks.py for that (works with both IR and MIR input).

I tried to use that tool for llvm/test/CodeGen/RISCV/rvv/add-vsetvli-gpr.mir, to see if it would be practical for the growing list of RVV tests (less than 40% of them currently use it), but it crashes with:
KeyError: 'vadd_vint64m1'.
Same problem for the RVV .ll tests I tried it with, but those didn't output MIR anyway.

I suspect it wasn't used because this is an IR->MIR test; there's utils/update_mir_test_checks.py for that (works with both IR and MIR input).

I tried to use that tool for llvm/test/CodeGen/RISCV/rvv/add-vsetvli-gpr.mir, to see if it would be practical for the growing list of RVV tests (less than 40% of them currently use it), but it crashes with:
KeyError: 'vadd_vint64m1'.

That's because there's a test to print assembly. MIR input tests are intended for unit-testing passes or sets of passes; if you want to be looking at the final assembly, that should be an IR test, but the MIR after finalize-isel should be more than sufficient in almost all cases.

Yes, we're certainly not moving away from update_llc_test_checks.py for the vector tests; I've used it in all of my work thus far. This test doesn't work perfectly with either the llc or mir scripts because it's IR -> MIR. The llc script does nothing on this test.

The mir script is more complicated, as it was used to generate the function checks in this MIR but it doesn't output anything for the YAML. So I had to add checks for the stack objects myself. I didn't want to include Assertions have been autogenerated by blah if it wasn't 100% auto-generated as it would give someone the impression they can just run the script again to regenerate the output. So I removed it. However, maybe the better approach would be to keep that line in but add an additional comment explaining this?

Yes, we're certainly not moving away from update_llc_test_checks.py for the vector tests; I've used it in all of my work thus far. This test doesn't work perfectly with either the llc or mir scripts because it's IR -> MIR. The llc script does nothing on this test.

The mir script is more complicated, as it was used to generate the function checks in this MIR but it doesn't output anything for the YAML. So I had to add checks for the stack objects myself. I didn't want to include Assertions have been autogenerated by blah if it wasn't 100% auto-generated as it would give someone the impression they can just run the script again to regenerate the output. So I removed it. However, maybe the better approach would be to keep that line in but add an additional comment explaining this?

Hm, I guess ideally we'd have an option for update_mir_test_checks.py to emit the stack info. I'll see if I can do that later today.

Hm, I guess ideally we'd have an option for update_mir_test_checks.py to emit the stack info. I'll see if I can do that later today.

@jrtc27 Were you able to progress on that front?

@luismarques any objections if I merge this before D99087? It contains "the original" test that's fixed by it.

luismarques accepted this revision.Apr 5 2021, 1:51 AM

Once update_mir_test_checks.py is tweaked we can start using it for this test, but let's merge it as-is for now. Thanks!

This revision is now accepted and ready to land.Apr 5 2021, 1:51 AM
This revision was automatically updated to reflect the committed changes.