Hi.

As an exercise, I am trying to implement a simple gcc pass
that unrolls the loops that have transactions.

The pass first identifies all the loops that have transactions,
and latter it unrolls the loop once by copying the loop body.

The pass works when I run gcc with -O0,
but it crashes gcc with -Ox (where x >= 0).

The diff in the attachment is made on the following branch:
remotes/origin/gcc-4_7-branch
git commit: 7551be1b393663d7034b30dc0be0560d7bab265c

Please, can somebody explain me what I am doing wrong?

Thanks,
Srdjan

P.S.

The code that I am transforming is the following:

/* hello.c */
int a;

int main(int argc, char* argv[]) {
  int n = atoi(argv[1]);
  int i;
  for (i = 0; i < n; ++i) {
    __transaction_atomic {
      ++a;
    }
  }
  printf("%d\n", a);
  return 0;
}

And I want to transform it to the:

/* hello.c */
int a;

int main(int argc, char* argv[]) {
  int n = atoi(argv[1]);
  int i;
  for (i = 0; i < n; ++i) {
    __transaction_atomic {
      ++a;
    }
    ++i;
    if (i >= n) break;
    __transaction_atomic {
      ++a;
    }
}
  printf("%d\n", a);
  return 0;
}

This is the compiler error message:

~/tm:  ~/prog/gcc2/bin/gcc-4.7 hello.c -fgnu-tm -static -funroll2 -v -O1
Using built-in specs.
COLLECT_GCC=/home/srdjan/prog/gcc2/bin/gcc-4.7
COLLECT_LTO_WRAPPER=/home/srdjan/prog/gcc2/libexec/gcc/x86_64-unknown-linux-gnu/4.7.3/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: ../gcc-repo/configure --prefix=/home/srdjan/prog/gcc2
--disable-bootstrap CFLAGS='-g3 -O0' --enable-languages=c
--disable-multilib --program-suffix=-4.7 --enable-checking=all
Thread model: posix
gcc version 4.7.3 20121115 (prerelease) (GCC)
COLLECT_GCC_OPTIONS='-fgnu-tm' '-static' '-funroll2' '-v' '-O1'
'-mtune=generic' '-march=x86-64' '-pthread'
 /home/srdjan/prog/gcc2/libexec/gcc/x86_64-unknown-linux-gnu/4.7.3/cc1
-quiet -v -D_REENTRANT hello.c -quiet -dumpbase hello.c -mtune=generic
-march=x86-64 -auxbase hello -O1 -version -fgnu-tm -funroll2 -o
/tmp/ccgjXgEO.s
GNU C (GCC) version 4.7.3 20121115 (prerelease) (x86_64-unknown-linux-gnu)
compiled by GNU C version 4.7.2, GMP version 5.0.2, MPFR version
3.1.0-p3, MPC version 0.9
GGC heuristics: --param ggc-min-expand=0 --param ggc-min-heapsize=0
ignoring nonexistent directory
"/home/srdjan/prog/gcc2/lib/gcc/x86_64-unknown-linux-gnu/4.7.3/../../../../x86_64-unknown-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
 /home/srdjan/prog/gcc2/lib/gcc/x86_64-unknown-linux-gnu/4.7.3/include
 /usr/local/include
 /home/srdjan/prog/gcc2/include
 /home/srdjan/prog/gcc2/lib/gcc/x86_64-unknown-linux-gnu/4.7.3/include-fixed
 /usr/include
End of search list.
GNU C (GCC) version 4.7.3 20121115 (prerelease) (x86_64-unknown-linux-gnu)
compiled by GNU C version 4.7.2, GMP version 5.0.2, MPFR version
3.1.0-p3, MPC version 0.9
GGC heuristics: --param ggc-min-expand=0 --param ggc-min-heapsize=0
Compiler executable checksum: 1e5f74bf79add0dcb61ed00160af061e
hello.c: In function ‘main’:
hello.c:11:3: warning: incompatible implicit declaration of built-in
function ‘printf’ [enabled by default]
hello.c:13:1: error: SSA_NAME_DEF_STMT is wrong
Expected definition statement:
# .MEM_21 = VDEF <.MEM_12>
    __transaction_atomic  // SUBCODE=[ GTMA_HAVE_LOAD GTMA_HAVE_STORE ]

Actual definition statement:
# .MEM_15 = VDEF <.MEM_12>
    __transaction_atomic  // SUBCODE=[ GTMA_HAVE_LOAD GTMA_HAVE_STORE ]
hello.c:13:1: internal compiler error: verify_ssa failed
Please submit a full bug report,
with preprocessed source if appropriate.
See <http://gcc.gnu.org/bugs.html> for instructions.

Attachment: gcc_unroll_tx_pass.diff
Description: Binary data

int a;

int main(int argc, char* argv[]) {
  int n = atoi(argv[1]);
  int i;
  for (i = 0; i < n; ++i) {
    __transaction_atomic {
      ++a;
    }
  }
  printf("%d\n", a);
  return 0;
}

Reply via email to