[Bug tree-optimization/92229] Optimization makes it impossible to read overflow flag
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92229 Ariel Torti changed: What|Removed |Added Status|WAITING |RESOLVED Resolution|--- |WONTFIX --- Comment #5 from Ariel Torti --- (In reply to jos...@codesourcery.com from comment #4) > On Sat, 26 Oct 2019, arieltorti14 at gmail dot com wrote: > > You can write an asm to access a flag, it will just be whatever value the > flag has for whatever code the compiler found matched the language-level > semantics of your code, which may have nothing to do with your notion of > what the flag "should" be. > > Language semantics are only matched to processor features at ABI > boundaries, not within functions (and not across calls to inline / static > functions etc. either, because those aren't ABI boundaries; any good > language feature in this area also needs to work in the presence of > multiple functions, and of inlining and similar transformations, not just > where the arithmetic is in the same function as the code that cares about > whether it overflowed). Fair point, I can see why it would be very problematic, didn't really knew the full scope when I considered the issue.
[Bug c/92230] Proposal to have builtin underflow detection function
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92230 Ariel Torti changed: What|Removed |Added Status|UNCONFIRMED |RESOLVED Resolution|--- |INVALID --- Comment #2 from Ariel Torti --- You got it right, I accidentally used the signed version and got confused by the result.
[Bug tree-optimization/92229] Optimization makes it impossible to read overflow flag
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92229 --- Comment #2 from Ariel Torti --- (In reply to jos...@codesourcery.com from comment #1) > Built-in functions related to integer overflow should be defined in terms > of the C abstract machine model, not in terms of processor flags. They should indeed, but what I want to implement here is a function that outputs the value of the OV flag, a behavior that cannot be achieved as a consequence of optimizations. > See recent WG14 discussions around this issue for various language design > ideas. Could you provide a link to the discussion in WG14 ? I'm not subscribed to it and I cannot find it.
[Bug middle-end/92230] New: Proposal to have builtin underflow detection function
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92230 Bug ID: 92230 Summary: Proposal to have builtin underflow detection function Product: gcc Version: 10.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: middle-end Assignee: unassigned at gcc dot gnu.org Reporter: arieltorti14 at gmail dot com Target Milestone: --- Right now GCC provides `__builtin_sub_overflow` to check for overflows during subtraction, but there's not way to check for underflow, other than maybe comparing the operators beforehand. Maybe it would be a good idea to have `__builtin_sub_underflow` functions which could be optimized at a greater level by reading the flags instead of doing integer comparisons. As a side note, is the behavior of `__builtin_sub_overflow` the intended one ?
[Bug tree-optimization/92229] New: Optimization makes it impossible to read overflow flag
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92229 Bug ID: 92229 Summary: Optimization makes it impossible to read overflow flag Product: gcc Version: 10.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: arieltorti14 at gmail dot com Target Milestone: --- I'm implementing a builtin to read the overflow flag. It is meant to be used to simply the overflow checking code, instead of doing: ov = __builtin_smul_overflow(a, b, ); if (ov) { ... } One could make the code more readable by using: res = a * b; if (__builtin_overflow_p()) { ... } The problem GCC optimizes many multiplication and addition operations by using `lea` which doesn't set the overflow flag, which makes it impossible to do the check. What approach could I take to implement this ? Do note that this builtin is only available on x86.
[Bug target/92137] [ia32] Missing documentation for ia32 builtins
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92137 --- Comment #6 from Ariel Torti --- (In reply to Eric Gallager from comment #5) > (In reply to Jakub Jelinek from comment #3) > > Those are intrinsics and most of them are documented in the Intel > > architecture manuals, or various web sites. Not sure it is a good idea to > > duplicate that documentation. > > Might be worthwhile to at least provide a link to the manuals or websites > then, if we're not going to duplicate the info contained in them... Could you provide an example on how you would add them ?
[Bug tree-optimization/92227] New: Optimizations on constant integer overflow checks lead to incorrect results
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92227 Bug ID: 92227 Summary: Optimizations on constant integer overflow checks lead to incorrect results Product: gcc Version: 10.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: arieltorti14 at gmail dot com Target Milestone: --- Created attachment 47113 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=47113=edit PoC generator When `fold_builtin_arith_overflow` optimizes the overflow check on integer constants it never sets the overflow flag on the flag register leading to incorrect results. Attached is a file containing two versions of a program showcasing the bug.
[Bug target/92137] [ia32] Missing documentation for ia32 builtins
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92137 --- Comment #2 from Ariel Torti --- (In reply to Richard Biener from comment #1) > You shouldn't use those, they are for internal use only. That's the reason > they are not documented. Yes, my mistake. I just read https://www.mail-archive.com/gcc@gcc.gnu.org/msg03310.html, where it says built-ins should not be documented. But if builtins are not documented their interfaces should, right ? As in, the functions below should be documented: __bsfd / _bit_scan_forward __bsrd / _bit_scan_reverse __bswapd / _bswap __crc32b / __crc32w __crc32d __popcntd / _popcnt32 __rdpmc / _rdpmc __rdtsc / _rdtsc __rdtscp / _rdtscp __rolb __rolw __rold __rorb __rorw __rord __pause __bsfq __bsrq __bswapq / _bswap64 __crc32q __popcntq / _popcnt64 __rolq __rorq __writeeflags __readeflags
[Bug driver/92137] New: [ia32] Missing documentation for ia32 builtins
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92137 Bug ID: 92137 Summary: [ia32] Missing documentation for ia32 builtins Product: gcc Version: 10.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: driver Assignee: unassigned at gcc dot gnu.org Reporter: arieltorti14 at gmail dot com Target Milestone: --- There are many implemented x86 builtins that are not documented, namely: __builtin_ia32_bsrsi __builtin_ia32_bsrdi __builtin_ia32_rolqi __builtin_ia32_rolhi __builtin_ia32_rorqi __builtin_ia32_rorhi __builtin_ia32_readeflags_u64 __builtin_ia32_writeeflags_u64 __builtin_ia32_readeflags_u32 __builtin_ia32_writeeflags_u32 I believe all of them should be documented but I may be wrong. I can document readeflags and writeeflags builtins if no one else will.