Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Singlepath: crashes on break from nested loop #19

Open
Emoun opened this issue Feb 16, 2019 · 3 comments
Open

Singlepath: crashes on break from nested loop #19

Emoun opened this issue Feb 16, 2019 · 3 comments

Comments

@Emoun
Copy link
Member

Emoun commented Feb 16, 2019

llc crashes on an assertion error when trying to compile a program, using singlepath, where an inner loop breaks out of an outer loop:

#include <stdio.h>

volatile int _1 = 1;

int init_func(int outer, int inner){
  int x = 0; 
  #pragma loopbound min 0 max 10
  for(int i = 0; i < outer; i++){
    #pragma loopbound min 0 max 4
    for(int k = 0; k < 5; k++){
      if( (x%100) == inner){
        goto breakLoops; // break out of both loops
      }
      x += _1;
    }
    x += 100;
  }
  breakLoops:
  return x;
}

int main(){
  int outer, inner;
  scanf("%d %d", &outer, &inner);
  printf("%d\n", init_func(outer, inner));
}

Compiling using the command patmos-clang main.c -mpatmos-singlepath=init_func results in the following error:

patmos-llc: /home/s123791/emoun/llvm/lib/Target/Patmos/PatmosSPReduce.cpp:1225: void {anonymous}::PatmosSPReduce::insertDefEdge(llvm::SPScope*, llvm::MachineBasicBlock&, unsigned int, llvm::SPScope::Edge): Assertion `!S->isSubHeader(&Node) || (RI.Scope->getParent() == S)' failed.
0  libLLVMSupport.so       0x00007fb9fe9ec39c llvm::sys::PrintStackTrace(_IO_FILE*) + 53
1  libLLVMSupport.so       0x00007fb9fe9ec62c
2  libLLVMSupport.so       0x00007fb9fe9ebfda
3  libc.so.6               0x00007fb9fe18a4b0
4  libc.so.6               0x00007fb9fe18a428 gsignal + 56
5  libc.so.6               0x00007fb9fe18c02a abort + 362
6  libc.so.6               0x00007fb9fe182bd7
7  libc.so.6               0x00007fb9fe182c82
8  libLLVMPatmosCodeGen.so 0x00007fba016669e7
9  libLLVMPatmosCodeGen.so 0x00007fba01666710
10 libLLVMPatmosCodeGen.so 0x00007fba016651fb
11 libLLVMPatmosCodeGen.so 0x00007fba01663362
12 libLLVMCodeGen.so       0x00007fba000cfd07 llvm::MachineFunctionPass::runOnFunction(llvm::Function&) + 95
13 libLLVMCore.so          0x00007fb9ff258946 llvm::FPPassManager::runOnFunction(llvm::Function&) + 330
14 libLLVMCore.so          0x00007fb9ff258abc llvm::FPPassManager::runOnModule(llvm::Module&) + 120
15 libLLVMCore.so          0x00007fb9ff258dbc
16 libLLVMCore.so          0x00007fb9ff25938f llvm::legacy::PassManagerImpl::run(llvm::Module&) + 267
17 libLLVMCore.so          0x00007fb9ff259569 llvm::legacy::PassManager::run(llvm::Module&) + 39
18 patmos-llc              0x000000000040ce99
19 patmos-llc              0x000000000040beac
20 libc.so.6               0x00007fb9fe175830 __libc_start_main + 240
21 patmos-llc              0x000000000040b779
Stack dump:
0.      Program arguments: /home/s123791/emoun/local/bin/patmos-llc -O0 -mforce-block-labels -disable-separate-nested-loops -mpatmos-singlepath=init_func -filetype=obj -o /tmp/a-104e35.bc.o /tmp/a-8e960e.bc
1.      Running pass 'Function Pass Manager' on module '/tmp/a-8e960e.bc'.
2.      Running pass 'Patmos Single-Path Reducer' on function '@init_func'
patmos-clang-3.4: error: unable to execute command: Aborted (core dumped)
patmos-clang-3.4: error: link  via llvm-link, opt and llc command failed due to signal (use -v to see invocation)
@Emoun
Copy link
Member Author

Emoun commented Feb 19, 2019

I tried manually executing all compilation steps. I.e. use patmos-clang to compile to bitcode and patmos-llc to compile to machine code. When llc is given the -O0 flag, the above assertion error is thrown. But if it is given -O1, -O2, or -O3 the compilation will succeed, but the execution will return the wrong result. E.g. when given the input 10 55 it returns 55 instead of 1050.

@Emoun
Copy link
Member Author

Emoun commented Feb 21, 2019

The same problem is seen when goto breakLoops is replaced by a return x. (the programs are equivalent)

@Emoun
Copy link
Member Author

Emoun commented Feb 23, 2019

Trying to continue an outer loop from an inner nested loop also given error. Take the following program, where we emulate continue using a goto:

#include <stdio.h>

int init_func(int pre, int inner, int post){
  int x = 0, y = 0, z = 0;
  outer_loop:
  #pragma loopbound min 0 max 9
  while(x < pre){
    x++;
    #pragma loopbound min 0 max 9
    for(int i = 0; i < inner; i++){
      y++;
      if(z >= post){
        goto outer_loop; //Continue outer loop
      }
    }
    z++;
  }
  return (x*10000) + (y*10) + z;
}

int main(){
  int pre, inner, post;
  scanf("%d %d %d", &pre, &inner, &post);
  printf("%d\n", init_func(pre, inner, post));
}

It compiles successfully and when run with the input 1 9 1 it correctly outputs 10091. But, given the input 1 10 1 we would expect the output 10101 but get 10000. I.e. only when the second input integer is at the loop bound (10) does it execute incorrectly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant