On Tue Mar 21 22:24:19 2023 +0000, Zebediah Figura wrote:
I don't like this assumption. Isn't this exactly the kind of thing we're trying to avoid? Then again, the obvious way to actually trigger this is insanity like float4 main() : sv_target { float x[3] = {0, 2, 3}; return x[x[1] = 1]; } which actually *does* yield 1. But it still makes me nervous. I'm not sure if there are other ways that this might do the wrong thing.
I wanted to avoid copying the load into a synthetic variable and then loading from it, since the generated IR before dce is getting increasingly bloated, which may make debugging difficult. But cases such as the one you mention didn't occur to me, good catch!
Adding a function call to your example actually makes the current implementation fail (retrieving 1.0 instead of 11.0):
```hlsl uint4 func(uint t) { return uint4(t + 0, t + 1, t + 2, t + 3); }
float4 main() : sv_target { return func(10)[func(0).y]; } ```
To solve this I had to bring a patch from the future (to support indexing non-hlsl_ir_load expressions) and change it a little. I also brought the related tests.