Summary: | [tree-ssa] make "fold" use alias information to optimize pointer comparisons | ||
---|---|---|---|
Product: | gcc | Reporter: | Dan Nicolaescu <dann> |
Component: | tree-optimization | Assignee: | Richard Biener <rguenth> |
Status: | RESOLVED FIXED | ||
Severity: | enhancement | CC: | dimhen, gabravier, gcc-bugs, msebor, sjames, zhongyunde |
Priority: | P2 | Keywords: | alias, missed-optimization, xfail |
Version: | tree-ssa | ||
Target Milestone: | --- | ||
See Also: |
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96564 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87313 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110103 |
||
Host: | Target: | ||
Build: | Known to work: | ||
Known to fail: | Last reconfirmed: | 2011-05-22 17:04:56 | |
Bug Depends on: | |||
Bug Blocks: | 19987, 113164, 61818, 65686 | ||
Attachments: | patch |
Description
Dan Nicolaescu
2004-02-01 18:22:51 UTC
Mine Enhancement request. Is this fixed? Subject: Re: [tree-ssa] make "fold" use alias information to optimize pointer comparisons "steven at gcc dot gnu dot org" <gcc-bugzilla@gcc.gnu.org> writes: > ------- Comment #3 from steven at gcc dot gnu dot org 2006-12-10 18:18 ------- > Is this fixed? No, it's not. Richi, this may be easy to fix on the AIB... Easy but dangerous ;) While looking at some unrelated issue, I noticed the following: _41 = operator new (28); ... if (_41 != &_S_empty_rep_storage) which happens with a simple use of std::string (with some extra inlining). __builtin_malloc(42)==&var is not optimized either, so it isn't (only) an issue with operator new. If the general case is too dangerous, maybe there is at least some subset that could safely be optimized? On Thu, 14 Aug 2014, glisse at gcc dot gnu.org wrote:
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=13962
>
> --- Comment #7 from Marc Glisse <glisse at gcc dot gnu.org> ---
> While looking at some unrelated issue, I noticed the following:
>
> _41 = operator new (28);
> ...
> if (_41 != &_S_empty_rep_storage)
>
> which happens with a simple use of std::string (with some extra inlining).
> __builtin_malloc(42)==&var is not optimized either, so it isn't (only) an issue
> with operator new.
>
> If the general case is too dangerous, maybe there is at least some subset that
> could safely be optimized?
Well, not sure if really "dangerous", but yes, doing pointer against
address-of-decl disambiguation should be easily possible.
I'll try to hack sth together later today.
Created attachment 33336 [details]
patch
Like this - does it help the particular case?
Note that one issue is that points-to doesn't track NULL-ness reliably
(like may-point to zero if it may point to a weak decl), and we drop
maybe-NULL-ness because we don't use it. Likewise we don't keep track
of pointers to CONST_DECLs or LABEL_DECLs or FUNCTION_DECLs (we simply
drop them on the floor rather than treating them as "anything").
The patch doesn't bootstrap which means it probably reveals bugs in
points-to. This is what I meant with "dangerous" ;)
(In reply to Richard Biener from comment #9) > Created attachment 33336 [details] > patch > > Like this - does it help the particular case? _S_empty_rep_storage has DECL_WEAK, so it doesn't help here :-( For GCC 7 we can now do ptr != decl (for certain kinds of decls). I have patches extending this to the ptr != ptr case but they need work because PTA needs to handle points-to NULL (aka nothing) and STRING_CST (and LABEL_DECL and FUNCTION_DECL, etc.) conservatively. Comparing LABEL_DECL against FUNCTION_DECL will also be interesting, so not sure if we can ever make this work (maybe glob LABEL_DECLs with their containing FUNCTION_DECLs for PTA purposes). Author: rguenth Date: Fri Apr 29 08:36:49 2016 New Revision: 235622 URL: https://gcc.gnu.org/viewcvs?rev=235622&root=gcc&view=rev Log: 2016-04-29 Richard Biener <rguenther@suse.de> PR tree-optimization/13962 PR tree-optimization/65686 * tree-ssa-alias.h (ptrs_compare_unequal): Declare. * tree-ssa-alias.c (ptrs_compare_unequal): New function using PTA to compare pointers. * match.pd: Add pattern for pointer equality compare simplification using ptrs_compare_unequal. * gcc.dg/uninit-pr65686.c: New testcase. Added: trunk/gcc/testsuite/gcc.dg/uninit-pr65686.c Modified: trunk/gcc/ChangeLog trunk/gcc/match.pd trunk/gcc/testsuite/ChangeLog trunk/gcc/tree-ssa-alias.c trunk/gcc/tree-ssa-alias.h *** Bug 78412 has been marked as a duplicate of this bug. *** *** Bug 84188 has been marked as a duplicate of this bug. *** *** Bug 110103 has been marked as a duplicate of this bug. *** The master branch has been updated by Richard Biener <rguenth@gcc.gnu.org>: https://gcc.gnu.org/g:f3e5f4c58591f5dacdd14a65ec47bbe310df02a0 commit r15-580-gf3e5f4c58591f5dacdd14a65ec47bbe310df02a0 Author: Richard Biener <rguenther@suse.de> Date: Mon Mar 11 11:17:32 2024 +0100 tree-optimization/13962 - handle ptr-ptr compares in ptrs_compare_unequal Now that we handle pt.null conservatively we can implement the missing tracking of constant pool entries (aka STRING_CST) and handle ptr-ptr compares using points-to info in ptrs_compare_unequal. PR tree-optimization/13962 PR tree-optimization/96564 * tree-ssa-alias.h (pt_solution::const_pool): New flag. * tree-ssa-alias.cc (ptrs_compare_unequal): Handle pointer-pointer compares. (dump_points_to_solution): Dump the const_pool flag, fix guard of flag dumping. * gimple-pretty-print.cc (pp_points_to_solution): Likewise. * tree-ssa-structalias.cc (find_what_var_points_to): Set the const_pool flag for STRING. (pt_solution_ior_into): Handle the const_pool flag. (ipa_escaped_pt): Initialize it. * gcc.dg/tree-ssa/alias-39.c: New testcase. * g++.dg/vect/pr68145.cc: Use -fno-tree-pta to avoid UB to manifest in transforms no longer vectorizing this testcase for an ICE. I'm closing this as fixed now. The feature is there, improvements can be made I guess but first get testcases that are not handled (combine with prange info is one item). |