Skip to content

singlepath: singlepath crashes when divide is used and compiled from bitcode  #14

@Emoun

Description

@Emoun

When I compile a program that includes a divide operation to bitcode (using patmos-clang -S) and then try to further compile it to assembly with patmos-llc, using the singlepath flag, it crashes.

Take this minimal code (we will refer to this as main.c):

volatile int _1 = 1;
volatile int _2 = 2;
int main(){
	return _2 / _1;
}

We compile it to LLVM bitcode using the command patmos-clang -S main.c -O2 without issue.
We then try to compile it to assembly using the command patmos-llc main.s -mpatmos-singlepath=main -O2. This fails with the following error:

[Single-path] Cannot rewrite call in main (indirect call?)
0  libLLVMSupport.so       0x00007f2c15841762 llvm::sys::PrintStackTrace(_IO_FILE*) + 50
1  libLLVMSupport.so       0x00007f2c15840f4c
2  libc.so.6               0x00007f2c1503ef20
3  libc.so.6               0x00007f2c1503ee97 gsignal + 199
4  libc.so.6               0x00007f2c15040801 abort + 321
5  libLLVMPatmosCodeGen.so 0x00007f2c175a5875
6  libLLVMCore.so          0x00007f2c15e50d09 llvm::legacy::PassManagerImpl::run(llvm::Module&) + 761
7  patmos-llc              0x00007f2c18008294
8  patmos-llc              0x00007f2c18006ec0
9  libc.so.6               0x00007f2c15021b97 __libc_start_main + 231
10 patmos-llc              0x00007f2c18006f3a
Stack dump:
0.      Program arguments: patmos-llc main.s -mpatmos-singlepath=main -O2
1.      Running pass 'Patmos Single-Path Mark (machine code)' on module 'main.s'.

Note that we are using -O2, but all other optimization levels result in the same issue. The issue is only present with the divide operator, changing it to a multiply makes the code compile successfully.
Additionally, the issue is only present when first compiling to bitcode and then using patmos-llc on it. If we instead use the command patmos-clang main.c the code compiles successfully. So the issue is caused by patmos-llc having to read bitcode.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions