microsoft / llvm-mctoll

llvm-mctoll
Other
816 stars 125 forks source link

Improve the Peephole optimization pass #135

Closed rcorcs closed 1 year ago

rcorcs commented 3 years ago
define dso_local i64 @foo(i64 %arg1, i32 %arg2) {
...
  %12 = add i64 %arg1, 8
  %13 = inttoptr i64 %12 to i64*
  store i64 %RCX9, i64* %13, align 1
...
}

The code above is transformed into the follow code:

define dso_local i64 @foo(i64 %arg1, i32 %arg2) {
...
  %12 = inttoptr i64 %arg1 to i8*
  %13 = getelementptr i8, i8* %12, i64 8
  %14 = bitcast i8* %13 to i64*
  store i64 %RCX9, i64* %14, align 1
...
}

For example, this transformation can improve future optimizations when foo is inlined. It also makes it easier to analyze whether %arg1 is always used as a pointer, depending on its inttoptr uses.

bharadwajy commented 3 years ago

Thanks @rcorcs This is an interesting change.

Does this code transformation enable better code generation - for example, is the generated code in a raised binary (i.e., generated from the raised .ll file) with this change more optimal than that without this peephole opt? How much closer (or better, if I may be ambitious :-)) is the raised binary - with this peephole opt - to the original binary?

Any chance you could share a test (C or assembly) source?

bharadwajy commented 1 year ago

Closing - no activity.