This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug tree-optimization/73714] New: [Regression 7] Incorrect unsigned long long arithmetic optimization
- From: "babokin at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Thu, 11 Aug 2016 12:55:37 +0000
- Subject: [Bug tree-optimization/73714] New: [Regression 7] Incorrect unsigned long long arithmetic optimization
- Auto-submitted: auto-generated
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=73714
Bug ID: 73714
Summary: [Regression 7] Incorrect unsigned long long arithmetic
optimization
Product: gcc
Version: 7.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: babokin at gmail dot com
Target Milestone: ---
Test case:
#include <iostream>
int var_s2 = 0;
int main () {
unsigned long long a = 1ULL << (57 - var_s2);
// result is truncated 0x3800000000000000ULL, it so should be 0.
int result = (int) (7679674331924488348ULL * a);
std::cout<<result<<"\n";
return 0;
}
O0 and O2 produce different results, while test case doesn't have undefined
behavior.
> g++ -O0 pr.cpp; ./a.out
0
> g++ -O2 pr.cpp; ./a.out
939524096
> g++ --version
g++ (Revision=239334/svn-rev:239337/) 7.0.0 20160810 (experimental)
Copyright (C) 2016 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
gcc 6.1.1 is fine ( (Revision=239178/svn-rev:239179/) 6.1.1 20160805)