Optimization LLVM insertvalue错误优化?

Optimization LLVM insertvalue错误优化?,optimization,code-generation,llvm,x86-64,Optimization,Code Generation,Llvm,X86 64,当我发出LLVM代码时,是否应该避免使用'insertvalue'指令与加载和存储结合使用? 当我使用它时,我总是得到糟糕的优化本机代码。请看以下示例: ; 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:1

当我发出LLVM代码时,是否应该避免使用'insertvalue'指令与加载和存储结合使用? 当我使用它时,我总是得到糟糕的优化本机代码。请看以下示例:

; 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”时,我得到了以下可怕的代码:

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指令更容易,我希望这些指令得到优化

我认为codegen很容易看出这样的事情是不好的:

        movq    56(%rax), %rsi
        movq    %rsi, 56(%rax)

首先,请注意,llc不进行任何IR级别的优化。因此,您应该运行opt来运行IR级别优化器集

然而,opt在这方面没有帮助。我希望标准的IR级优化器能够以某种方式将这些东西规范化为gep


请提交LLVM PR,这看起来像是错过了优化

您正在使用哪个LLVM版本?