0

I transform the following llvm-IR

; Function Attrs: noinline norecurse nounwind uwtable
define i32 @main() #0{
entry:
%sub = sub nsw i32 5, 3
%cmp = icmp slt i32 %sub, 3
br i1 %cmp, label %if.then, label %if.else

if.then:                                          ; preds = %entry
%mul = mul nsw i32 %sub, 2
br label %if.end

if.else:                                          ; preds = %entry
%sub1 = sub nsw i32 %sub, 3
br label %if.end

if.end:                                           ; preds = %if.else, 
%if.then
%y.0 = phi i32 [ %mul, %if.then ], [ %sub1, %if.else ]
%sub2 = sub nsw i32 %sub, %y.0
%add = add nsw i32 %sub, %y.0
ret i32 0
}

to assembly code for x86_64-unknown-linux-gnu using llc sample.ll generated assembly code:

    .text
    .file   "phi.cpp"
    .globl  main                    # -- Begin function main
    .p2align        4, 0x90
    .type   main,@function
main:                                   # @main
    .cfi_startproc
# BB#0:                                 # %entry
    pushq   %rbp
.Lcfi0:
    .cfi_def_cfa_offset 16
.Lcfi1:
    .cfi_offset %rbp, -16
    movq    %rsp, %rbp
.Lcfi2:
    .cfi_def_cfa_register %rbp
    xorl    %eax, %eax
    testb   %al, %al
    xorl    %eax, %eax
    popq    %rbp
    retq
.Lfunc_end0:
    .size   main, .Lfunc_end0-main
    .cfi_endproc
                                    # -- End function

The register in the above code: %rbp is the base pointer, which points to the base of the current stack frame, and %rsp is the stack pointer, which points to the top of the current stack frame and operand are store in %eax and %al for arithmatic operation but in can't find the instruction where the value is load in %eax and %al register I also want to know

  1. How llc is handling phi node on assembly level
4

1 回答 1

1

lli默认为-O2,并且您的代码以常量表达式开头sub nsw i32 5, 3。因此,您的函数基本上什么都不做,LLVM 应该保留的唯一一件事就是使 EAX 无效。

如果你运行lli -O0 your.ll,你会得到很多冗长的代码,这些代码会在堆栈和寄存器加载上执行溢出。

顺便说一句,有一对通行证被调用mem2regreg2mem可以从 SSA 形式来回转换代码。具体来说,这些通道会将phi节点转换为分支,并在 IR 中引入显式存储和加载。

于 2017-09-08T06:51:46.340 回答