Walter's talk on D backend
user1234
user1234 at 12.de
Mon Sep 23 12:31:27 UTC 2024
On Monday, 23 September 2024 at 11:49:27 UTC, claptrap wrote:
> On Monday, 23 September 2024 at 11:03:45 UTC, user1234 wrote:
>> On Monday, 23 September 2024 at 09:43:50 UTC, claptrap wrote:
>
>> I cant reply for DMD but as I detect a confusion, let me add
>> something about that... SSA is not about variables it's about
>> nodes assigned uniquely once
>>
>> So if X is a variable then each use of it is either a load or
>> a store. (there can be bit cast and ptr arithmetic too, but
>> let keep thing simple.)
>>
>>
>> (pseudo LLVM IR, to illustrate, with X, a global uint)
>>
>> ```
>> %1 = i32 load ptr @X
>> %3 = i32 add i32 %1, i32 %1
>> i32 store ptr @X, i32 %3
>> (LLVM does not make store reuseable, that'd be be a
>> non-sense)
>>
>>
>> You see variables are not accessed as-is, either you have a
>> load or a store.
>> An SSA node is what starts with "%"
>> ```
>>
>
> That's counter to everything I've read about it. It is defined
> as "variables are only assigned once", so each time you assign
> a new value to X, it gets a suffix, so each assignment to X
> becomes a new variable X0,X1... and so on.
>
> It makes it explicit what definition reaches what uses of X.
> Even through all the control flow. That's actually what makes
> SSA useful.
>
> A quick google says LLVM IR is SSA for registers but not memory
> locations. So I don't think your example shows anything.
>
> What would show SSA is if you cant assign to a register
> multiple times. Eg..
>
> ```
> %1 = i32 load ptr @X
> %2 = i32 load ptr @Y
> %2 = i32 add i32 %1, i32 %2
> ```
>
> That would be invalid in SSA
Yes. That's impossible. Also the reasoning that each SSA
instruction is a state of a register is not totally exact (that's
not yours tho). At the IR stage the notion of register does not
exist *yet*. However it's true that it's often the case.
Otherwise, my example showed that reasoning at the level of a
variable is not relevant, for DCE at least. Actually an unused
load should never be generated.
What *can* happen is something like
```
X + 1; // %1 = load ...
// %2 = add
```
then DCE will realize that %2 is never used and drop %2 and %1.
IIRC D detects such cases at the front-end level and emits an
error: "expression <...> has not effect".
More information about the Digitalmars-d
mailing list