public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/113632] New: Range info for a^CST could be improved
@ 2024-01-28 6:23 pinskia at gcc dot gnu.org
2024-01-28 6:25 ` [Bug tree-optimization/113632] Range info for a^CSTP2-1 could be improved in some cases pinskia at gcc dot gnu.org
2024-03-04 14:53 ` amacleod at redhat dot com
0 siblings, 2 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-01-28 6:23 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113632
Bug ID: 113632
Summary: Range info for a^CST could be improved
Product: gcc
Version: 14.0
Status: UNCONFIRMED
Keywords: missed-optimization
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: pinskia at gcc dot gnu.org
Target Milestone: ---
Take:
```
void dummy();
_Bool f(unsigned long a)
{
_Bool cmp = a > 8192;
if (cmp) goto then; else goto e;
then:
unsigned long t = __builtin_clzl(a); // [0,50]
t^=63; // [13,63]
return t >= 13;
e:
dummy();
return 0;
}
```
Currently after the t^=63; we get:
```
# RANGE [irange] int [1, 63] MASK 0x3f VALUE 0x0
_7 = _1 ^ 63;
```
But this could/should be improved to [13,63].
If we change to using minus instead:
```
t = 63 - t;
```
We get the better range and the comparison (t >= 13) is optimized away.
```
Folding statement: t_10 = 63 - t_9;
Global Exported: t_10 = [irange] long unsigned int [13, 63] MASK 0x3f VALUE 0x0
Not folded
```
Yes this should up in real code, see the LLVM issue for more information on
that.
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug tree-optimization/113632] Range info for a^CSTP2-1 could be improved in some cases
2024-01-28 6:23 [Bug tree-optimization/113632] New: Range info for a^CST could be improved pinskia at gcc dot gnu.org
@ 2024-01-28 6:25 ` pinskia at gcc dot gnu.org
2024-03-04 14:53 ` amacleod at redhat dot com
1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-01-28 6:25 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113632
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Summary|Range info for a^CST could |Range info for a^CSTP2-1
|be improved |could be improved in some
| |cases
Severity|normal |enhancement
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug tree-optimization/113632] Range info for a^CSTP2-1 could be improved in some cases
2024-01-28 6:23 [Bug tree-optimization/113632] New: Range info for a^CST could be improved pinskia at gcc dot gnu.org
2024-01-28 6:25 ` [Bug tree-optimization/113632] Range info for a^CSTP2-1 could be improved in some cases pinskia at gcc dot gnu.org
@ 2024-03-04 14:53 ` amacleod at redhat dot com
1 sibling, 0 replies; 3+ messages in thread
From: amacleod at redhat dot com @ 2024-03-04 14:53 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113632
Andrew Macleod <amacleod at redhat dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |amacleod at redhat dot com
--- Comment #1 from Andrew Macleod <amacleod at redhat dot com> ---
(In reply to Andrew Pinski from comment #0)
> Take:
> ```
> void dummy();
> _Bool f(unsigned long a)
> {
> _Bool cmp = a > 8192;
> if (cmp) goto then; else goto e;
> then:
> unsigned long t = __builtin_clzl(a); // [0,50]
> t^=63; // [13,63]
> return t >= 13;
> e:
> dummy();
> return 0;
> }
> ```
>
> Currently after the t^=63; we get:
> ```
> # RANGE [irange] int [1, 63] MASK 0x3f VALUE 0x0
> _7 = _1 ^ 63;
> ```
>
> But this could/should be improved to [13,63].
>
> If we change to using minus instead:
> ```
> t = 63 - t;
> ```
>
> We get the better range and the comparison (t >= 13) is optimized away.
> ```
> Folding statement: t_10 = 63 - t_9;
> Global Exported: t_10 = [irange] long unsigned int [13, 63] MASK 0x3f VALUE
> 0x0
> Not folded
> ```
>
> Yes this should up in real code, see the LLVM issue for more information on
> that.
I think the current implementation of "operator_bitwise_xor::wi_fold ()" in
range-op.cc was simply ported from the original version we used in the old VRP
code. so it is neither multi-range awre, nor been enhanced.
If you put a break point there, you'll see its getting:
(gdb) p lh_lb.dump()
[0], precision = 32
$1 = void
(gdb) p lh_ub.dump()
[0x32], precision = 32
$2 = void
(gdb) p rh_ub.dump()
[0x3f], precision = 32
$3 = void
(gdb) p rh_lb.dump()
[0x3f], precision = 32
$4 = void
One could conceivable do something much better than the general masking stuff
that goes on if rh_lb == rh_ub. I suspect we could probably do a better job in
general, but have never looked at it.
It also looks like we make some minor attempts with signed values in
wi_optimize_signed_bitwise_op (), but again, I do not think anyone has tried
to make this code do anything new yet.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-03-04 14:53 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-28 6:23 [Bug tree-optimization/113632] New: Range info for a^CST could be improved pinskia at gcc dot gnu.org
2024-01-28 6:25 ` [Bug tree-optimization/113632] Range info for a^CSTP2-1 could be improved in some cases pinskia at gcc dot gnu.org
2024-03-04 14:53 ` amacleod at redhat dot com
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).