Propagate stores of stack addresses into other local variables
Pointers to the base address of arrays often get stored and then loaded
multiple time. This change adds an optimization pass to replace these
loads with the result of the alloca of the array, and eliminates the
allocas of the pointer variables.
The PropagateAlloca unit test without this optimization produces:
sub rsp,38h
mov dword ptr [rsp+8],16h
cmp ecx,0
je 000002543C4E407E
lea rax,[rsp+8]
mov qword ptr [rsp],rax
mov rax,qword ptr [rsp]
mov eax,dword ptr [rax]
add rsp,38h
ret
With the optimization pass it becomes:
sub rsp,38h
mov dword ptr [rsp],16h
cmp ecx,0
jne 0000015DC3B33074
mov eax,dword ptr [rsp]
add rsp,38h
ret
Also add a couple of unit tests for corner cases where the propagation
is not safe to perform.
Bug: b/179279298
Change-Id: I784899319bf5360f47c6fbc22fb82134d135dbfc
Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/52468
Presubmit-Ready: Nicolas Capens <nicolascapens@google.com>
Tested-by:
Nicolas Capens <nicolascapens@google.com>
Reviewed-by:
Antonio Maiorano <amaiorano@google.com>
Showing
Please
register
or
sign in
to comment