Use clang to generate LLVM IR with -O3, how to visit these load operations after -reg2mem

Hi, all

I want to instrument load/store operations in LLVM IR. And I find the LLVM IR generated with flag -o3 is much more efficient than -o0, so I try to instrument on these optimized LLVM IR, but, some load operations are changed to Phi loads. Then, I try the -reg2mem flag to remove these phi nodes.
The problems are:

  1. I use visitLoadInst to collect these load operations, and it seems I cannot reach these loads that are generated by reg2mem? What is the reason?
  2. Is there any way to compile with -O3 but not generate phi nodes ?

Hi, all

I want to instrument load/store operations in LLVM IR. And I find the LLVM
IR generated with flag -o3 is much more efficient than -o0, so I try to
instrument on these optimized LLVM IR, but, some load operations are changed
to Phi loads. Then, I try the -reg2mem flag to remove these phi nodes.
The problems are:
1) I use visitLoadInst to collect these load operations, and it seems I
cannot reach these loads that are generated by reg2mem? What is the reason?

Clang doesn't generate optimized IR - so if your instrumentation is in
Clang's IRGen (clang/lib/CodeGen) it won't see these. Clang generates
the unoptimized IR (you can see it with -Xclang -disable-llvm-optzns)

2) Is there any way to compile with -O3 but not generate phi nodes ?

Not likely - without that it'd disable a lot of LLVM's optimization power.

- David

Best Regards!
Eric Lew

Hi, all

I want to instrument load/store operations in LLVM IR. And I find the LLVM
IR generated with flag -o3 is much more efficient than -o0, so I try to
instrument on these optimized LLVM IR, but, some load operations are changed
to Phi loads. Then, I try the -reg2mem flag to remove these phi nodes.
The problems are:

  1. I use visitLoadInst to collect these load operations, and it seems I
    cannot reach these loads that are generated by reg2mem? What is the reason?

Clang doesn’t generate optimized IR - so if your instrumentation is in
Clang’s IRGen (clang/lib/CodeGen) it won’t see these. Clang generates
the unoptimized IR (you can see it with -Xclang -disable-llvm-optzns)

I do instrumentation in the opt of llvm. Does clang itself do some optimizations that speed up applications with -O3 compared to -O0?

Best Regards!
Eric Lew

Hi, all

I want to instrument load/store operations in LLVM IR. And I find the LLVM
IR generated with flag -o3 is much more efficient than -o0, so I try to
instrument on these optimized LLVM IR, but, some load operations are
changed
to Phi loads. Then, I try the -reg2mem flag to remove these phi nodes.
The problems are:
1) I use visitLoadInst to collect these load operations, and it seems I
cannot reach these loads that are generated by reg2mem? What is the
reason?

Clang doesn't generate optimized IR - so if your instrumentation is in
Clang's IRGen (clang/lib/CodeGen) it won't see these. Clang generates
the unoptimized IR (you can see it with -Xclang -disable-llvm-optzns)

I do instrumentation in the opt of llvm. Does clang itself do some
optimizations that speed up applications with -O3 compared to -O0?

A little bit, but not much.

Hi, David
Thanks for your reply.