Add rules to strip away unneeded type casts in expressions

Programming / Compilers / GCC - tnfchris [138bc75d-0d04-0410-961f-82ee72b054a4] - 26 July 2019 13:05 EDT

This patch moves part of the type conversion code from convert.c to match.pd because match.pd is able to apply these transformations in the presence of intermediate temporary variables.

Concretely it makes both these cases behave the same

float e = (float)a * (float)b;
*c = (_Float16)e;

and

*c = (_Float16)((float)a * (float)b);

gcc/ChangeLog:

- convert.c (convert_to_real_1): Move part of conversion code...
- match.pd: ...To here.

gcc/testsuite/ChangeLog:

- gcc.dg/type-convert-var.c: New test.

f3abf7fd679 Add rules to strip away unneeded type casts in expressions
gcc/ChangeLog | 5 ++
gcc/convert.c | 86 --------------------
gcc/match.pd | 134 ++++++++++++++++++++++++--------
gcc/testsuite/ChangeLog | 4 +
gcc/testsuite/gcc.dg/type-convert-var.c | 9 +++
5 files changed, 121 insertions(+), 117 deletions(-)

Upstream: gcc.gnu.org


  • Share