[llvm-dev] Optimization Problem

Garba Peter via llvm-dev llvm-dev at lists.llvm.org
Sat Apr 27 04:27:52 PDT 2019


I try to understand why llvm can't optimize this small piece of code.
My expectation is that the IR will be optimized to a " ret i64 2101545.
But somehow the alias analysis fails when the pointer is casted to an integer value,
so the dead code eliminator can't optimize it away.

Could someone explain to me why this is failing and if there is a solution for that ?

I can trick the alias analysis by setting %5 to a concrete integer so the code can be optimized further,
but I'm still wondering why llvm can't do it.


define dso_local i64 @func(i64, i64, i64) local_unnamed_addr #0 {
  %3 = alloca [100 x i64], align 16
  %4 = getelementptr inbounds [100 x i64], [100 x i64]* %3, i64 0, i64 2
  %5 = ptrtoint i64* %4 to i64
  %6 = add i64 %5, -8
  %7 = inttoptr i64 %6 to i64*
  store i64 0, i64* %7, align 8
  %8 = add i64 %5, -12
  %9 = inttoptr i64 %8 to i32*
  store i32 0, i32* %9, align 4
  %10 = add i64 %5, -16
  %11 = inttoptr i64 %10 to i32*
  store i32 0, i32* %11, align 16
  ret i64 2101545
This message and any attachments are intended solely for the addressees and may contain confidential information. Any unauthorized use or disclosure, either whole or partial, is prohibited.
E-mails are susceptible to alteration. Our company shall not be liable for the message if altered, changed or falsified. If you are not the intended recipient of this message, please delete it and notify the sender.
Although all reasonable efforts have been made to keep this transmission free from viruses, the sender will not be liable for damages caused by a transmitted virus.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20190427/833c6f92/attachment.html>

More information about the llvm-dev mailing list