LLVM insertvalue不好优化吗? [英] LLVM insertvalue bad optimized?
问题描述
在发出LLVM代码时,应避免将"insertvalue"指令与装入和存储结合使用吗? 使用它时,我总是得到糟糕的优化本机代码.看下面的例子:
Should I avoid using the 'insertvalue' instruction combined with load and store when I emit LLVM code? I always get bad optimized native code when I use it. Look at the following example:
; ModuleID = 'mod'
target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
target triple = "x86_64-pc-linux-gnu"
%A = type { i64, i64, i64, i64, i64, i64, i64, i64 }
@aa = external global %A*
define void @func() {
entry:
%a1 = load %A** @aa
%a2 = load %A* %a1
%a3 = insertvalue %A %a2, i64 3, 3
store %A %a3, %A* %a1
ret void
}
当我运行"llc -o--O3 mod.ll"时,我得到了这个可怕的代码:
When I run "llc -o - -O3 mod.ll", I get this horrible code:
func: # @func
.Ltmp0:
.cfi_startproc
# BB#0: # %entry
movq aa(%rip), %rax
movq (%rax), %r8
movq 8(%rax), %r9
movq 16(%rax), %r10
movq 32(%rax), %rdi
movq 40(%rax), %rcx
movq 48(%rax), %rdx
movq 56(%rax), %rsi
movq %rsi, 56(%rax)
movq %rdx, 48(%rax)
movq %rcx, 40(%rax)
movq %rdi, 32(%rax)
movq %r10, 16(%rax)
movq %r9, 8(%rax)
movq %r8, (%rax)
movq $3, 24(%rax)
ret
但是我想看到的是这个
func: # @func
.Ltmp0:
.cfi_startproc
# BB#0: # %entry
movq aa(%rip), %rax
movq $3, 24(%rax)
ret
我当然可以使用getelementptr之类的东西,但有时生成insertvalue和extractvalue指令更容易,我希望对它们进行优化...
Of course I can use getelementptr or something, but sometimes it is easier to generate insertvalue and extractvalue instructions, and I want these to be optimized...
我认为,代码源很容易发现类似这样的事情是不好的:
I think it would be quite easy for the codegen to see that things like these are bad:
movq 56(%rax), %rsi
movq %rsi, 56(%rax)
推荐答案
首先,请注意,llc不会进行任何IR级优化.因此,您应该运行opt来运行IR级优化程序集.
First, note that llc does not do any IR-level optimizations. So, you should run opt to run the set of IR-level optimizers.
但是,opt对此无济于事.我希望标准的IR级优化程序可以将这些东西规范化为gep.
However, opt does not help in this. I'd expect that standard IR-level optimizers canonicalize the stuff into gep somehow.
请提交LLVM PR,这似乎错过了优化!
Please file a LLVM PR, this looks like a missed optimization!
这篇关于LLVM insertvalue不好优化吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!