[llvm-dev] llvm.trap() from -O1 optimization

Mehdi Amini via llvm-dev llvm-dev at lists.llvm.org
Tue Dec 13 21:40:49 PST 2016


> 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



More information about the llvm-dev mailing list