[Bug middle-end/85989] New: Incorrect result for example involving unary minus in a loop

2018-05-29 Thread ketan.surender at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85989

Bug ID: 85989
   Summary: Incorrect result for example involving unary minus in
a loop
   Product: gcc
   Version: 6.3.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: middle-end
  Assignee: unassigned at gcc dot gnu.org
  Reporter: ketan.surender at gmail dot com
  Target Milestone: ---

Created attachment 44208
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=44208&action=edit
Preprocessed reproduction file

Please see the attached file 'standalone.i'. When I run this in -O0 I see the
result

gcc -Wall -Wstrict-aliasing=0 -O0 standalone.i -o standalone
./standalone

--> 0
--> 0

This is what I expect. If I compile with '-O1' I see

gcc -Wall -Wstrict-aliasing=0 -O1 standalone.i -o standalone
./standalone

--> 8
--> 8

Which is unexpected. I poked around in gdb and stared at the asm in godbolt and
it seems like the negation is being omitted in the following loop:

  for (b_P5 = 0; b_P5 < 8; b_P5++) {
P26 = P29;
P29 = -(int)*P5;
  }

Here is my gcc info

Using built-in specs.
COLLECT_GCC=[SNIP]/glnxa64/gcc-6.3.0/bin/gcc
COLLECT_LTO_WRAPPER=[SNIP]/glnxa64/gcc-6.3.0/bin/../libexec/gcc/x86_64-pc-linux-gnu/6.3.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: [SNIP]/sources/gcc-6.3/configure
--with-gmp=[SNIP]/glnxa64/gcc-6.3/gmp-4.3 --with-mpfr=[SNIP]/gcc-6.3/mpfr
--with-mpc=[SNIP]/gcc-6.3/mpc --enable-languages=c,c++,fortran
--with-bugurl=[SNIP],_Debugging --enable-shared --enable-linker-build-id
--enable-plugin --enable-checking=release --enable-multiarch --enable-gold
--enable-ld=default --enable-libstdcxx-time=no
--prefix=[SNIP]/glnxa64/gcc-6.3.0 --with-pkgversion='MW GCC 6.3.0-GLIBC2.12'
--with-tune=generic --with-system-zlib --enable-multilib
--with-multilib-list=m32,m64 --with-arch-directory=amd64 --with-arch-32=i586
--with-abi=m64
Thread model: posix
gcc version 6.3.0 (MW GCC 6.3.0-GLIBC2.12)

[Bug tree-optimization/86632] New: Incorrect value copied into output array with -O3 ftree-loop-vectorize

2018-07-22 Thread ketan.surender at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86632

Bug ID: 86632
   Summary: Incorrect value copied into output array with -O3
ftree-loop-vectorize
   Product: gcc
   Version: 6.3.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: tree-optimization
  Assignee: unassigned at gcc dot gnu.org
  Reporter: ketan.surender at gmail dot com
  Target Milestone: ---

I am observing incorrect results for the following function with -O3

static void mDiscBlocks2_repro_output(void)
{
  /* local scratch DWork variables */
  int32_T ForEach_itr_p;
  real_T rtb_ImpAsg_InsertedFor_Out1_a_d[6];
  real_T rtb_ImpAsg_InsertedFor_Out2_a_o[3];
  int32_T i;

  for (ForEach_itr_p = 0; ForEach_itr_p < 3; ForEach_itr_p++) {
rtb_ImpAsg_InsertedFor_Out2_a_o[ForEach_itr_p] =
  mDiscBlocks2_repro_DW.CoreSubsys[ForEach_itr_p].Memory1_PreviousInput;
rtb_ImpAsg_InsertedFor_Out1_a_d[ForEach_itr_p << 1] =
  mDiscBlocks2_repro_DW.CoreSubsys[ForEach_itr_p].Memory_PreviousInput[0];
rtb_ImpAsg_InsertedFor_Out1_a_d[1 + (ForEach_itr_p << 1)] =
  mDiscBlocks2_repro_DW.CoreSubsys[ForEach_itr_p].Memory_PreviousInput[1];
  }

  /* KS REQUIRED */
  for (i = 0; i < 6; i++) {
mDiscBlocks2_repro_Y.Out14[i] = rtb_ImpAsg_InsertedFor_Out1_a_d[i];
  }

  /* KS REQUIRED */
  mDiscBlocks2_repro_Y.Out15[0] = rtb_ImpAsg_InsertedFor_Out2_a_o[0];
  mDiscBlocks2_repro_Y.Out15[1] = rtb_ImpAsg_InsertedFor_Out2_a_o[1];
  mDiscBlocks2_repro_Y.Out15[2] = rtb_ImpAsg_InsertedFor_Out2_a_o[2];
}

This code copies some global data to a local array, then copies the local array
to a global. 

mDiscBlocks2_repro_DW.CoreSubsys[0-2].Memory1_PreviousInput -->
rtb_ImpAsg_InsertedFor_Out2_a_o[0-2] -->  mDiscBlocks2_repro_Y.Out15[0-2]
mDiscBlocks2_repro_DW.CoreSubsys[0-2].Memory_PreviousInput[0] -->
rtb_ImpAsg_InsertedFor_Out1_a_d[0,2,4] --> mDiscBlocks2_repro_Y.Out14[0,2,4]
mDiscBlocks2_repro_DW.CoreSubsys[0-2].Memory_PreviousInput[1] -->
rtb_ImpAsg_InsertedFor_Out1_a_d[1,3,5] --> mDiscBlocks2_repro_Y.Out14[1,3,5]

For the global 'mDiscBlocks2_repro_Y.Out14' I am observing the incorrect value
at index 2. The issue goes away if I add the switch -fno-tree-loop-vectorize. 

I looked at the generated asm a little and can see the incorrect assignment.
For some reason it writes to element 2 before writing the remaining elements.

Here is my gcc info

Using built-in specs.
COLLECT_GCC=[SNIP]/glnxa64/gcc-6.3.0/bin/gcc
COLLECT_LTO_WRAPPER=[SNIP]/glnxa64/gcc-6.3.0/bin/../libexec/gcc/x86_64-pc-linux-gnu/6.3.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: [SNIP]/sources/gcc-6.3/configure
--with-gmp=[SNIP]/glnxa64/gcc-6.3/gmp-4.3 --with-mpfr=[SNIP]/gcc-6.3/mpfr
--with-mpc=[SNIP]/gcc-6.3/mpc --enable-languages=c,c++,fortran
--with-bugurl=[SNIP],_Debugging --enable-shared --enable-linker-build-id
--enable-plugin --enable-checking=release --enable-multiarch --enable-gold
--enable-ld=default --enable-libstdcxx-time=no
--prefix=[SNIP]/glnxa64/gcc-6.3.0 --with-pkgversion='MW GCC 6.3.0-GLIBC2.12'
--with-tune=generic --with-system-zlib --enable-multilib
--with-multilib-list=m32,m64 --with-arch-directory=amd64 --with-arch-32=i586
--with-abi=m64
Thread model: posix
gcc version 6.3.0 (MW GCC 6.3.0-GLIBC2.12)

[Bug tree-optimization/86632] Incorrect value copied into output array with -O3 ftree-loop-vectorize

2018-07-22 Thread ketan.surender at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86632

--- Comment #1 from Ketan  ---
Will add attachment in a moment.

[Bug tree-optimization/86632] Incorrect value copied into output array with -O3 ftree-loop-vectorize

2018-07-22 Thread ketan.surender at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86632

--- Comment #2 from Ketan  ---
Created attachment 44419
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=44419&action=edit
Reproduction Files

Contents of archive
- compile.sh : Compiles and runs code in -O0 (correct result), -O3 (incorrect
result), -O3 -fno-tree-loop-vectorize (correct result)
- main.c : Required source file
- mDiscBlocks2_repro.c : Required source file
- mDiscBlocks2_repro.h : Required header file. Defines various global
structures used by the code.

[Bug tree-optimization/86632] Incorrect value copied into output array with -O3 ftree-loop-vectorize

2018-07-22 Thread ketan.surender at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86632

--- Comment #3 from Ketan  ---
Example execution output:

Compile and run with -O1
Out14[0] = 0.00
Out14[1] = 0.00
Out14[2] = 0.00
Out14[3] = 0.00
Out14[4] = 0.00
Out14[5] = 0.00

Out15[0] = 75.00
Out15[1] = 75.00
Out15[2] = 75.00

Compile and run with -O3
Out14[0] = 0.00
Out14[1] = 0.00
Out14[2] = 75.00
Out14[3] = 0.00
Out14[4] = 0.00
Out14[5] = 0.00

Out15[0] = 75.00
Out15[1] = 75.00
Out15[2] = 75.00

Compile and run with -O3 -fno-tree-loop-vectorize
Out14[0] = 0.00
Out14[1] = 0.00
Out14[2] = 0.00
Out14[3] = 0.00
Out14[4] = 0.00
Out14[5] = 0.00

Out15[0] = 75.00
Out15[1] = 75.00
Out15[2] = 75.00

[Bug middle-end/83234] New: Aggressive loop optim warning for loop iteration that cannot happen

2017-11-30 Thread ketan.surender at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83234

Bug ID: 83234
   Summary: Aggressive loop optim warning for loop iteration that
cannot happen
   Product: gcc
   Version: 6.3.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: middle-end
  Assignee: unassigned at gcc dot gnu.org
  Reporter: ketan.surender at gmail dot com
  Target Milestone: ---

Created attachment 42759
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=42759&action=edit
Reproduction File

I have an example program with the code:

  for (j = 0; j < 3; j++) {
for (i = 1; i <= 3 - j; i++) {
  out8[i - 1][j] = (int8_T)(i + j);
}

for (i = 4 - j; i < 4; i++) {
  out8[i - 1][j] = in15[(i + j) - 3];
}
  }

that produces the warning

hankel_script.c: In function ‘hankel_script’:
hankel_script.c:235:32: warning: iteration 2147483644 invokes undefined
behavior [-Waggressive-loop-optimizations]
   out8[i - 1][j] = in15[(i + j) - 3];
 ~~~^~~~
hankel_script.c:234:5: note: within this loop
 for (i = 4 - j; i < 4; i++) {

The loop bounds have been defined with constants such that iteration 2147483644
cannot happen.

Repro:
gcc -c -O2 hankel_script.i

I do not see the warning with -O3 or -O1.

My gcc version is 6.3. See details below. I am able to reproduce this using
x86-64 gcc 7.2 on https://gcc.godbolt.org/.

COLLECT_GCC=gcc
Target: x86_64-pc-linux-gnu
Configured with: [SCRUB]/sources/gcc-6.3/configure
--with-gmp=[SCRUB]/gcc-6.3/gmp-4.3 --with-mpfr=[SCRUB]/gcc-6.3/mpfr
--with-mpc=[SCRUB]/gcc-6.3/mpc --enable-languages=c,c++,fortran
--with-bugurl=[SCRUB],_Debugging --enable-shared --enable-linker-build-id
--enable-plugin --enable-checking=release --enable-multiarch --enable-gold
--enable-ld=default --prefix=[SCRUB]/gcc-6.3.0 --with-pkgversion='MW GCC
6.3.0-GLIBC2.11' --with-tune=generic --with-system-zlib --enable-multilib
--with-multilib-list=m32,m64 --with-arch-directory=amd64 --with-arch-32=i586
--with-abi=m64
gcc version 6.3.0 (MW GCC 6.3.0-GLIBC2.11)

[Bug middle-end/83234] Aggressive loop optim warning for loop iteration that cannot happen

2017-11-30 Thread ketan.surender at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83234

--- Comment #1 from Ketan  ---
I am on Debian 8

[Bug tree-optimization/66280] New: internal compiler error: in vect_get_vec_def_for_operand, at tree-vect-stmts.c:1322

2015-05-25 Thread ketan.surender at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66280

Bug ID: 66280
   Summary: internal compiler error: in
vect_get_vec_def_for_operand, at
tree-vect-stmts.c:1322
   Product: gcc
   Version: 4.7.2
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: tree-optimization
  Assignee: unassigned at gcc dot gnu.org
  Reporter: ketan.surender at gmail dot com
  Target Milestone: ---

Created attachment 35622
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=35622&action=edit
preprocessed reproduction file

Hitting an internal compilation error for the attached repro.i file.

g++ -c -std=c++98 -pedantic -Wno-long-long -fwrapv -fPIC -O3 -fno-loop-optimize
repro.i

dtodoublessingleststscript4.cpp: In function ‘void
dtodoublessingleststscript4(short int, const cint16_T*, short int*, cint16_T*,
int*, cint32_T*, cint32_T*, int*, cint32_T*, cint16_T*, cint32_T*, int*, int*,
cint32_T*, cint32_T*, int*, cint32_T*, int*, int*, cint32_T*, cint32_T*,
cint16_T*, short int*, short int*, short int*, short int*)’:
dtodoublessingleststscript4.cpp:102:6: internal compiler error: in
vect_get_vec_def_for_operand, at tree-vect-stmts.c:1322
Please submit a full bug report,
with preprocessed source if appropriate.
See <http://gcc.gnu.org/bugs.html> for instructions.

I am seeing this on a Debian 7 machine.

g++ -v
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/SNIP/glnxa64/gcc-4.7.2/libexec/gcc/x86_64-unknown-linux-gnu/4.7.2/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: /SNIP/gcc-4.7/configure --prefix=/SNIP/glnxa64/gcc-4.7.2
--with-gmp=/SNIP/glnxa64/gcc-4.7/gmp --with-mpfr=/SNIP/glnxa64/gcc-4.7/mpfr
--with-mpc=/SNIP/glnxa64/gcc-4.7/mpc --enable-languages=c,c++,fortran
--with-as=/SNIP/glnxa64/gcc-4.7.2/bin/as
--with-ld=/SNIP/glnxa64/gcc-4.7.2/bin/ld
Thread model: posix
gcc version 4.7.2 (GCC)

[Bug tree-optimization/68389] New: internal compiler error: in tree_low_cst, at tree.h:4431

2015-11-17 Thread ketan.surender at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68389

Bug ID: 68389
   Summary: internal compiler error: in tree_low_cst, at
tree.h:4431
   Product: gcc
   Version: 4.7.2
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: tree-optimization
  Assignee: unassigned at gcc dot gnu.org
  Reporter: ketan.surender at gmail dot com
  Target Milestone: ---

Created attachment 36742
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=36742&action=edit
preprocessedReproFile

For the attached file I am seeing an internal compiler error with -O3 

COLLECT_GCC_OPTIONS='-v' '-save-temps' '-c' '-ansi' '-pedantic'
'-Wno-long-long' '-fwrapv' '-fPIC' '-O3' '-D' 'MODEL=xOutOfOrderWrites_exec'
'-D' 'HAVESTDIO' '-D' 'USE_RTMODEL' '-D' 'UNIX' '-I' 'anotherPath/gccBugs' '-I'
'anotherPath/gccBugs/codegen/dll/xOutOfOrderWrites' '-I' 'aPath/extern/include'
'-I' 'aPath/simulink/include' '-I' 'aPath/rtw/c/src' '-I'
'aPath/rtw/c/src/ext_mode/common' '-I' 'aPath/rtw/c/ert' '-o'
'xOutOfOrderWrites.o' '-mtune=generic' '-march=x86-64'

/anotherAnotherPath/glnxa64/gcc-4.7.2/libexec/gcc/x86_64-unknown-linux-gnu/4.7.2/cc1
-fpreprocessed xOutOfOrderWrites.i -quiet -dumpbase xOutOfOrderWrites.c
-mtune=generic -march=x86-64 -auxbase-strip xOutOfOrderWrites.o -O3 -pedantic
-Wno-long-long -ansi -version -fwrapv -fPIC -o xOutOfOrderWrites.s

xOutOfOrderWrites.c: In function ‘xOutOfOrderWrites’:
xOutOfOrderWrites.c:222:6: internal compiler error: in tree_low_cst, at
tree.h:4431

This can be reproduced with the attached preprocessed file:

gcc -c -O3 xOutOfOrderWrites.i

GCC Version Info:

GNU C (GCC) version 4.7.2 (x86_64-unknown-linux-gnu)
compiled by GNU C version 4.7.2, GMP version 4.3.2, MPFR version 2.4.2,
MPC version 0.8.2
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
GNU C (GCC) version 4.7.2 (x86_64-unknown-linux-gnu)
compiled by GNU C version 4.7.2, GMP version 4.3.2, MPFR version 2.4.2,
MPC version 0.8.2
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: aa64e71d3fbf9c408b8b9eecd9fda662

[Bug tree-optimization/68389] internal compiler error: in tree_low_cst, at tree.h:4431

2015-11-20 Thread ketan.surender at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68389

--- Comment #2 from Ketan  ---
I tried 5.2 and did not see the issue.