arcana-lab / noelle

NOELLE Offers Empowering LLVM Extensions
MIT License
72 stars 35 forks source link

inliner segfaults when xoring data from file #79

Closed a11ce closed 1 year ago

a11ce commented 1 year ago

The following test causes a segfault in the inliner:

#include <stdio.h>

int main(int argc, char *argv[]) {
  FILE *f = fopen("test.c", "r");
  char ch;
  char check = 0;
  while ((ch = getc(f)) != 'c') {
    check ^= ch;
  }
  printf("check(getc): %d\n", check);
  return 0;
}

Adding instead of xoring works fine. Xoring elements of an array is also fine.


To replicate, create a new regression test with the above test.c and run make. This will run:

clang -I../../include/threadpool/include -emit-llvm -O1 -Xclang -disable-llvm-passes -c test.c -o test.bc
opt -O0 test.bc -o test.bc
clang++ -O3 -c -emit-llvm test.bc -o baseline.bc
clang++ -O3 baseline.bc -o baseline
noelle-prof-coverage test.bc baseline_with_runtime_prof -lm -lstdc++ -lpthread
./baseline_with_runtime_prof
mv default.profraw pre_profiles.profraw
noelle-meta-prof-embed pre_profiles.profraw test.bc -o baseline_pre.bc
# this next step will crash
noelle-pre baseline_pre.bc -noelle-pdg-verbose=1 -noelle-verbose=2 -noelle-min-hot=0 -noelle-inliner-avoid-hoist-to-main
a11ce commented 1 year ago

https://github.com/arcana-lab/noelle/blob/8a2f889934c49f0e8a846c749da0db0b5cfa86d0/src/core/loop_scc_attributes/src/BinaryReductionSCC.cpp#L90

firstAccumI is null here. Looking at AccumulatorOpInfo.cpp, xor isn't supported. I can add this, but if there are other operations that could be misclassified as BinaryReduction then SCCDAGAttrs.cpp should be made aware of the supported ops.