Ashay Rane via llvm-dev
2016-Dec-14 05:31 UTC
[llvm-dev] llvm.trap() from -O1 optimization
Hello, This is likely to be some small issue, but I am unable to figure out the solution. The following code, when run through `opt' with the -O1 flag, replaces the call to foo() with a call to llvm.trap() followed by an `unreachable' instruction. ====================target datalayout = "e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64" target triple = "armv7-unknown-linux-gnu" define arm_aapcs_vfpcc void @foo() { entry: ret void } define arm_aapcs_vfpcc void @bar() { entry: call void @foo() ret void } ==================== If I drop the "arm_aapcs_vfpcc" for foo(), then the `unreachable' instruction and the call to trap() are no longer introduced in the code. I am running `opt' on a 64-bit x86 machine. I have synced llvm, clang, and compiler-rt to the latest commits, but that did not help. $ clang --version clang version 4.0.0 (https://github.com/llvm-mirror/clang.git 631f1e728a6903f320a40e7b5035a63acd0acdc7) (https://github.com/llvm-mirror/llvm.git 23156f19246677a896ffbda72eadbcbbc1c47964) Any ideas on how to prevent the unreachable instruction? Thanks! Ashay
Mehdi Amini via llvm-dev
2016-Dec-14 05:40 UTC
[llvm-dev] llvm.trap() from -O1 optimization
> On Dec 13, 2016, at 9:31 PM, Ashay Rane via llvm-dev <llvm-dev at lists.llvm.org> wrote: > > Hello, > > This is likely to be some small issue, but I am unable to figure out > the solution. The following code, when run through `opt' with the -O1 > flag, replaces the call to foo() with a call to llvm.trap() followed > by an `unreachable' instruction. > > ====================> target datalayout = "e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64" > target triple = "armv7-unknown-linux-gnu" > > define arm_aapcs_vfpcc void @foo() { > entry: > ret void > } > > define arm_aapcs_vfpcc void @bar() { > entry: > call void @foo()You’re not using the right calling convention here: you need call arm_aapcs_vfpcc void @foo(). Instcombine detects the mismatch, knows it is incorrect, and thus optimize away the call with “undefined behavior”-like code. — Mehdi> ret void > } > ====================> > If I drop the "arm_aapcs_vfpcc" for foo(), then the `unreachable' > instruction and the call to trap() are no longer introduced in the > code. > > I am running `opt' on a 64-bit x86 machine. I have synced llvm, clang, > and compiler-rt to the latest commits, but that did not help. > > $ clang --version > clang version 4.0.0 (https://github.com/llvm-mirror/clang.git > 631f1e728a6903f320a40e7b5035a63acd0acdc7) > (https://github.com/llvm-mirror/llvm.git > 23156f19246677a896ffbda72eadbcbbc1c47964) > > Any ideas on how to prevent the unreachable instruction? Thanks! > > Ashay > _______________________________________________ > LLVM Developers mailing list > llvm-dev at lists.llvm.org > http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
Tim Northover via llvm-dev
2016-Dec-14 14:25 UTC
[llvm-dev] llvm.trap() from -O1 optimization
On 13 December 2016 at 21:31, Ashay Rane via llvm-dev <llvm-dev at lists.llvm.org> wrote:> target datalayout = "e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64" > target triple = "armv7-unknown-linux-gnu"You probably also want the triple "armv7-unknown-linux-gnueabihf". Straight away that would make your arm_aapcs_vfpcc annotations redundant because that's the default. Also, plain "gnu" is a really weird old ABI that LLVM doesn't actually support so you could easily get strange behaviour from the backend not dealing with it properly. And even if the backend gets it right somehow, your surrounding libraries are almost certainly not "gnu". Cheers. Tim.