public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/111780] New: Missed optimization of '(t*4)/(t*2) -> 2'
@ 2023-10-12 7:56 652023330028 at smail dot nju.edu.cn
2023-10-12 8:34 ` [Bug tree-optimization/111780] " rguenth at gcc dot gnu.org
0 siblings, 1 reply; 2+ messages in thread
From: 652023330028 at smail dot nju.edu.cn @ 2023-10-12 7:56 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111780
Bug ID: 111780
Summary: Missed optimization of '(t*4)/(t*2) -> 2'
Product: gcc
Version: 14.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: 652023330028 at smail dot nju.edu.cn
Target Milestone: ---
Hello, we found some optimizations (regarding Arithmetic optimization) that GCC
may have missed. We would greatly appreicate if you can take a look and let us
know what you think.
Given the following code:
https://godbolt.org/z/G9rWK7c3q
int n1;
void func1(int a){
if(a>1&&a<4) n1=(a+a+a+a)/(a+a);
}
Different from PR 111718, this missed optimization appears to be due to a
missed pattern: (t*4)/(t*2) -> 2
# DEBUG BEGIN_STMT
# RANGE [irange] int [8, 8][12, 12] NONZERO 0xc
_3 = a_7(D) * 4;
# RANGE [irange] int [4, 4][6, 6] NONZERO 0x6
_4 = a_7(D) * 2;
# RANGE [irange] int [1, 3] NONZERO 0x3
_5 = _3 / _4;
# .MEM_9 = VDEF <.MEM_8(D)>
n1D.2761 = _5;
Or a more general pattern: (t*m)/(t*n) -> m/n , where m and n are constants.
Thank you very much for your time and effort! We look forward to hearing from
you.
^ permalink raw reply [flat|nested] 2+ messages in thread
* [Bug tree-optimization/111780] Missed optimization of '(t*4)/(t*2) -> 2'
2023-10-12 7:56 [Bug tree-optimization/111780] New: Missed optimization of '(t*4)/(t*2) -> 2' 652023330028 at smail dot nju.edu.cn
@ 2023-10-12 8:34 ` rguenth at gcc dot gnu.org
0 siblings, 0 replies; 2+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-10-12 8:34 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111780
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |missed-optimization
Status|UNCONFIRMED |NEW
Last reconfirmed| |2023-10-12
Ever confirmed|0 |1
--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
Confirmed. Same for
int foo (int a, int b, int c)
{
return 2*c*(a*b) / (a*b);
}
note when we cannot remove the division like for
c*a / d*a
we have to watch out for -INT_MIN / -1, but I think the only way
this would not invoke undefined behavior before the transform is
when the factor is equal to -1 but then c*a cannot be -INT_MIN so
it should be safe in general, not only when m and n are constants?
Note we cannot re-associate for the transform.
We only have
/* Simplify (t * 2) / 2) -> t. */
(for div (trunc_div ceil_div floor_div round_div exact_div)
(simplify
(div (mult:c @0 @1) @1)
(if (ANY_INTEGRAL_TYPE_P (type))
(if (TYPE_OVERFLOW_UNDEFINED (type))
@0
#if GIMPLE
(with {value_range vr0, vr1;}
(if (INTEGRAL_TYPE_P (type)
&& get_range_query (cfun)->range_of_expr (vr0, @0)
&& get_range_query (cfun)->range_of_expr (vr1, @1)
&& range_op_handler (MULT_EXPR).overflow_free_p (vr0, vr1))
@0))
#endif
))))
but not the case with two multiplies.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-10-12 8:34 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-12 7:56 [Bug tree-optimization/111780] New: Missed optimization of '(t*4)/(t*2) -> 2' 652023330028 at smail dot nju.edu.cn
2023-10-12 8:34 ` [Bug tree-optimization/111780] " rguenth at gcc dot gnu.org
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).