-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[AutoDiff][DebugInfo] Properly transfer location info from debug_value into alloc_stack in pullback cloner #42245
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
Conversation
Tagging @rxwei |
Did you mean SR-15849 instead? |
Oh, yes, sorry! |
test/AutoDiff/compiler_crashers_fixed/sr15849-invalid-debug-info.swift
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, one last question inline.
@rxwei @adrian-prantl Will you please trigger ci for me? |
@swift-ci Please test. |
@swift-ci please test linux |
@swift-ci please test |
@swift-ci please test linux |
Weird, now we have difference between Linux and Mac. The SIL is different though:
Linux:
Note that on Linux we allocate two separate stack slots for members of |
After some plumbing with cross compiling I was able to reproduce linux issue with cross-compiler. Looking |
Looks like the problem is exposed by SIL SROA as it uses
I guess the real question is: per SIL specification we do not need op_deref on debug_value for alloca instruction. What if the debug info is attached to alloca itself? Do we need to use pointer type or value type? I'd lean for value type as things like Another question is as follows:
Here we're having have two locations for "self" – one in alloca w/o explicit type and another one on debug_value. Do we consider this debug info as consistent? |
@swift-ci Please test. |
I'll defer to @adrian-prantl on the question above. |
You might want to enable |
@adrian-prantl Yes, they refer to the same
|
Right, sorry. If the explicit type is missing, the type is the one from of the alloc_stack.
When it's attached to the alloca and there's no expression, the value type from the alloca instruction is used.
Yes. There can be many debug_value instructions for one variable. This is particularly important for optimized code as the debug_values follow the value around as it's moved from one SSA value to another. In your example the debug_value is redundant, but benign. |
How we'd treat |
However, here (in example) we're having clash in SIL debug info verifier. As first it sees alloca's type (pointer one) and after this – debug_value one (value type). Hence the clash and incompatibility :) |
@mshockwave do you happen to remember the design decisions that went into pointer versus value types? |
I think that the debug_value should really be
|
@adrian-prantl it cannot be – %11 is of |
Sorry, I should really read your example more carefully. %11 is the load of the alloca, not the alloca, so the value type is correct. |
What I meant to say is that the debug info in |
@adrian-prantl Great, thanks! What do we do with
|
The fragment looks fine to me and is consistent with the tests: https://github.com/apple/swift/blob/b5ed5f81409887abfe449a55274d88394a58f317/test/DebugInfo/sroa_mem2reg.sil#L60 |
So, op_fragment should imply op_deref then? The last (Linux) test fail was because we had pointer type + op_fragment and corresponding value type debug info for the same incoming arg. This caused debug info verifier to fail. In my last commit I changed sroa to use value type debug info (and fixed tests) |
In this example:
there is no implied deref. The debug_value describes the new location of the |
@adrian-prantl Fair enough and thanks for the clarification (my mental model was "set of operations to obtain a value of variable"). Then I guess the debug info verifier should be fixed as it is not clear what it should check conceptually Consider the following cases:
It seems that we'd need to check that the debug info for the value is consistent, therefore:
Does this look as the intended behaviour and consistent with the implied debug info verified design? Or maybe I'm missing something? |
There seems to be some traffic after I was tagged, so I'll try to clarify from the earlier one:
Given the original alloc_stack instruction
The suggested mental model here: Another highlight is that "model", as well as the following
In which case the source variable name of I agree this is not so straightforward, but the DWARF standard coined this (model) and both LLVM and SIL are following it.
Sorry but I think the type of
Slightly tangent: But is the second |
@mshockwave Thanks for the clarifications!
Yes, typo, should be value type, not pointer.
Well, I'm essentially copying real cases I've seen in wild :) The |
… need to drop op_deref expression
@mshockwave @adrian-prantl Thanks for the clarifications! I refined the patch and relaxed the checks in SIL verifier to accommodate for the location changes like in case 1 above. Please review. PS: It seems we have plenty of cases when |
LGTM |
@adrian-prantl Will you please ping CI for me? :) |
@swift-ci test |
@adrian-prantl @BradLarson @rxwei Will you please merge the PR for me? Thanks! |
In order to transfer debug info from
debug_value
toalloc_stack
we need to dropop_ref
debug expression, as the latter instruction represents the location and not the value itself. Also, fix the debug info verifier as variable type was deduced fromalloc_stack
/alloc_box
improperly: pointer type of instruction itself was used instead of underlying object type.The issue is only exposed when both optimizations (SIL mem2reg at least) and debug info are enabled
Resolves SR-15849