]> git.ipfire.org Git - thirdparty/gcc.git/commit
fab: Manaully build gimple rather than depend on gimplifier for stdarg functions
authorAndrew Pinski <andrew.pinski@oss.qualcomm.com>
Mon, 22 Sep 2025 05:30:18 +0000 (22:30 -0700)
committerAndrew Pinski <andrew.pinski@oss.qualcomm.com>
Fri, 3 Oct 2025 14:01:03 +0000 (07:01 -0700)
commitaca8f47ffe98ed0f410c8e9cbe376749f68e4e71
tree18f2759f7177313d3d215b8cd4c85ff06df339bf
parent554a54b97ea935802bc66679ebb882ad61adf897
fab: Manaully build gimple rather than depend on gimplifier for stdarg functions

This code dates before gimple tuples was around. So it uses both MODIFY_EXPR and
INDIRECT_REF :).
For `__builtin_va_start(ptr, 0)` it exands into:
```
_t = __builtin_next_arg (0);
*ptr = _t;
```
We need to get a new VDEF for the next arg call so we don't need to do a
ssa update too.

For `__builtin_va_copy(ptr, b)`, it expands into:
```
*ptr = b;
```
Which is still a store.

For `__builtin_va_end(ptr)`, we change it into a GIMPLE_NOP.

Before optimize_stdarg_builtin would return a tree and then
pass_fold_builtins::execute would set todo to include
TODO_update_address_taken for a non-null result.
Since now optimize_stdarg_builtin returns a bool, the path that had
set the todo is no longer taken (the result variable is still NULL).
Setting the todo to include TODO_update_address_taken when the call to
optimize_stdarg_builtin succeeds to be able to get the same effect as
before.

That is:
before we had:
```
result = optimize_stdarg_builtin(...);
...
if (!result) continue;
todo |= TODO_update_address_taken;
```
Now after this change we have:
result = NULL_TREE;
...
if (optimize_stdarg_builtin(...))
  todo |= TODO_update_address_taken;
if (!result) continue;
```
Also since optimize_stdarg_builtin will remove the part of taking an
address of a local variable and in this case fab is the last pass
where this happens, TODO_update_address_taken is needed to change the
va args in some cases to not forced to memory variables.

Note this code will be moved into gimple_fold later on. This is part of the
reason for updating this code. The other side is this simplifies the code
too.

Changes since v1:
* v2: expand commit message.

gcc/ChangeLog:

* tree-ssa-ccp.cc (optimize_stdarg_builtin): Mannually create the
gimple statements instead of depending on the gimplifier.
(pass_fold_builtins::execute): Handle updated call to optimize_stdarg_builtin.

Signed-off-by: Andrew Pinski <andrew.pinski@oss.qualcomm.com>
gcc/tree-ssa-ccp.cc