diff options
author | Aldy Hernandez <aldyh@redhat.com> | 2022-08-31 14:41:29 +0200 |
---|---|---|
committer | Aldy Hernandez <aldyh@redhat.com> | 2022-09-01 13:19:08 +0200 |
commit | 0550e306d4b5aaf7bdb6e908d265dbaa63344271 (patch) | |
tree | e61be0d9aa862d268cae28a2f69c4bcf8f89aed0 | |
parent | e9b0dd2afe7a9e8a3033340dfa26ec606930eef5 (diff) | |
download | gcc-0550e306d4b5aaf7bdb6e908d265dbaa63344271.zip gcc-0550e306d4b5aaf7bdb6e908d265dbaa63344271.tar.gz gcc-0550e306d4b5aaf7bdb6e908d265dbaa63344271.tar.bz2 |
Implement ranger folder for __builtin_signbit.
Now that we keep track of the signbit, we can use it to fold __builtin_signbit.
I am assuming I don't have try too hard to get the actual signbit
number and 1 will do. Especially, since we're inconsistent in trunk whether
we fold the builtin or whether we calculate it at runtime.
abulafia:~$ cat a.c
float nzero = -0.0;
main(){
printf("0x%x\n", __builtin_signbit(-0.0));
printf("0x%x\n", __builtin_signbit(nzero));
}
abulafia:~$ gcc a.c -w && ./a.out
0x1
0x80000000
It is amazing that we've been failing to fold something as simple as
this:
if (x > 5.0)
num = __builtin_signbit (x);
It does the right thing now :-P.
gcc/ChangeLog:
* gimple-range-fold.cc
(fold_using_range::range_of_builtin_int_call): Add case for
CFN_BUILT_IN_SIGNBIT.
gcc/testsuite/ChangeLog:
* gcc.dg/tree-ssa/vrp-float-signbit-1.c: New test.
-rw-r--r-- | gcc/gimple-range-fold.cc | 20 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/tree-ssa/vrp-float-signbit-1.c | 12 |
2 files changed, 32 insertions, 0 deletions
diff --git a/gcc/gimple-range-fold.cc b/gcc/gimple-range-fold.cc index b0b2210..d8497fc 100644 --- a/gcc/gimple-range-fold.cc +++ b/gcc/gimple-range-fold.cc @@ -1023,6 +1023,26 @@ fold_using_range::range_of_builtin_int_call (irange &r, gcall *call, break; } + case CFN_BUILT_IN_SIGNBIT: + { + arg = gimple_call_arg (call, 0); + frange tmp; + if (src.get_operand (tmp, arg)) + { + if (tmp.get_signbit ().varying_p ()) + return false; + if (tmp.get_signbit ().yes_p ()) + { + tree one = build_one_cst (type); + r.set (one, one); + } + else + r.set_zero (type); + return true; + } + break; + } + case CFN_BUILT_IN_TOUPPER: { arg = gimple_call_arg (call, 0); diff --git a/gcc/testsuite/gcc.dg/tree-ssa/vrp-float-signbit-1.c b/gcc/testsuite/gcc.dg/tree-ssa/vrp-float-signbit-1.c new file mode 100644 index 0000000..3fa783e --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/vrp-float-signbit-1.c @@ -0,0 +1,12 @@ +// { dg-do compile } +// { dg-options "-O2 -fdump-tree-evrp" } + +int num; + +void func(float x) +{ + if (x > 5.0) + num = __builtin_signbit (x); +} + +// { dg-final { scan-tree-dump-times "num = 0;" 1 "evrp" } } |