Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Conversation

@CarolEidt
Copy link

Fix #14539

@CarolEidt
Copy link
Author

@sdmaclea - I'm not certain this is the right fix, but I added an assert that the type of op2 matches the type of the LOCKADD before it modifies that to TYP_VOID. It eliminates the assert in crossgen'ing of SPC.dll. I'll wait to hear from you whether there are tests for which the assert in gentree.cpp will fail.

// TODO-ARM64-CQ Evaluate whether this is necessary
// https://github.com/dotnet/coreclr/issues/14346
getEmitter()->emitIns_R_R(INS_ldaxr, emitTypeSize(treeNode), loadReg, addrReg);
getEmitter()->emitIns_R_R(INS_ldaxr, emitActualTypeSize(data), loadReg, addrReg);

Choose a reason for hiding this comment

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

We generally use emitTypeSize for loads. Since it does not force the size to a general purpose register size.

Here it doesn't effect functionality, but I would prefer to change it to be consistent.

expr->SetOperRaw(GT_LOCKADD);
#ifndef _TARGET_ARM64_
assert(genActualType(expr->gtType) == genActualType(expr->gtOp.gtOp2->gtType));
expr->gtType = TYP_VOID;

Choose a reason for hiding this comment

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

I think the importer should be changed to set the type to VOID on import of GT_LOCKADD too. I think this must be missing unless emitTypeSize for TYP_VOID doesn't assert or return 0.

Copy link
Author

Choose a reason for hiding this comment

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

I think that, theoretically, it is defined to return the data type. It's in Compiler::gtExtractSideEffList that it changes it to TYP_VOID when its result isn't used. However, I don't know if it ever actually returns a result.

@sdmaclea
Copy link

Something between gentree and codegen is changing the type of the addend

On my tip w/o your original change, I added three asserts, that the addend matched the atomic node type.

  1. Importer (creation of atomic HIR)
  2. gentree (your assert from this patch)
  3. codegen (since I still have the TYP_VOID assignment #ifdef out)

This test is hitting the codegen assert on my tip.
JIT/Regression/JitBlue/GitHub_10714/GitHub_10714/GitHub_10714.sh

@sdmaclea
Copy link

gdb from failing test case JIT/Regression/JitBlue/GitHub_10714/GitHub_10714/GitHub_10714.sh:

Assert failure(PID 44402 [0x0000ad72], Thread: 44402 [0xad72]): Assertion failed 'emitTypeSize(treeNode) == emitTypeSize(data->gtType)' in 'GitHub_10714:Test():int' (IL size 16)

    File: /home/vmjenkins/workspace/Dotnet/build_and_test/src/jit/codegenarm64.cpp Line: 2732
    Image: /home/sdmaclea/coreoverlay/corerun


Thread 1 "corerun" received signal SIGABRT, Aborted.
0x0000ffffb7bb1528 in __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:54
54      ../sysdeps/unix/sysv/linux/raise.c: No such file or directory.
(gdb) frame 9
#9  0x0000ffffb31d11b0 in CodeGen::genLockedInstructions (this=0x4d6ce0, treeNode=0x4d9da8) at /home/vmjenkins/workspace/Dotnet/build_and_test/src/jit/codegenarm64.cpp:2732
(gdb) print data->gtType
$1 = var_types::TYP_SHORT
(gdb) print treeNode->gtType
$2 = var_types::TYP_INT
(gdb) print data->isContainedIntOrIImmed()
$3 = false
(gdb) print data->OperGet()
$4 = genTreeOps::GT_IND

So the addend is from a indirect TYP_SHORT address. During lowering, there must have been a cast dropped. Since on ARM64 the type of op2 would normally be evaluated with emitActualTypeSize by consumers.

I think GTF_NOVALUE, might be a better way to signal this behavior.

If we want to continue setting GT_LOCKADD->gtType to TYP_VOID, then using emitActualTypSize instead of emitTypSize would solve the problems with atomics here.

@CarolEidt
Copy link
Author

I think GTF_NOVALUE, might be a better way to signal this behavior.

I would like to avoid the use of GTF_NOVALUE. In fact, I hope to eventually elimiante it.

If we want to continue setting GT_LOCKADD->gtType to TYP_VOID, then using emitActualTypSize instead of emitTypSize would solve the problems with atomics here.

I think that's the right approach.

@CarolEidt
Copy link
Author

@sdmaclea - Do you agree that this is an appropriate and correct fix?
@dotnet/jit-contrib PTAL

@CarolEidt
Copy link
Author

@dotnet/jit-contrib - I meant to ping on this, not on the bug.

Copy link

@briansull briansull left a comment

Choose a reason for hiding this comment

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

Looks Good

@CarolEidt CarolEidt merged commit 7631617 into dotnet:master Oct 18, 2017
@sdmaclea
Copy link

@CarolEidt Thanks, I had to go offline last night due to a household appliance failure

@sdmaclea
Copy link

@CarolEidt BTW, there may still be an issue for 64 bit atomics if the addend is an indirect small type, when there should be a carry into the high 32 bits. I would guess the problem exist on all platforms now, but I am not sure. There is certainly no coverage for this case.

@CarolEidt
Copy link
Author

there may still be an issue for 64 bit atomics if the addend is an indirect small type, when there should be a carry into the high 32 bits. I would guess the problem exist on all platforms now, but I am not sure. There is certainly no coverage for this case.

Agreed. I opened #14557 because I think the implementation of the interlocked operations would be cleaner and less error-prone if they took an indirection as their op1. That indirection would hold the correct type. I'll add a note there that we should add better test coverage.

@mikedn mikedn mentioned this pull request Jun 5, 2018
@CarolEidt CarolEidt deleted the Fix14539 branch July 16, 2018 19:11
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants