Optimizer to remove duplicate loads?

Which optimizer would remove duplicate, or unneeded loads? In my
generator I end up having a lot of the same load. For example here I
keep loading "@pt" which will always be the same value.

  %16 = load %1** @pt, align 8
  %17 = getelementptr inbounds %1* %16, i64 0, i32 2, i32 0
  %18 = load i32* %17, align 4
  call void @trace_integer(i32 %18)
  %19 = load %1** @pt, align 8
  %20 = getelementptr inbounds %1* %19, i64 0, i32 2, i32 1
  %21 = load i32* %20, align 4
  call void @trace_integer(i32 %21)
  %22 = load %1** @pt, align 8
  %23 = getelementptr inbounds %1* %22, i64 0, i32 0

Hi,

Which optimizer would remove duplicate, or unneeded loads? In my
generator I end up having a lot of the same load. For example here I
keep loading "@pt" which will always be the same value.

in order to do this, the optimizers need to know that the call to
@trace_integer does not modify the contents of @pt. Is it logically
possible for them to deduce this? If not, no optimizer can do what
you want.

Ciao, Duncan.

Yeah, I thought about that and then realized in this context they could
not (it's an external function). Is there some attribute I can mark the
functions with however that would allow the optimizers to understand
it's safe not to reload?

From: llvmdev-bounces@cs.uiuc.edu [mailto:llvmdev-bounces@cs.uiuc.edu]
On Behalf Of edA-qa mort-ora-y
Subject: Re: [LLVMdev] Optimizer to remove duplicate loads?

Is there some attribute I can mark the functions with however that would
allow the optimizers to understand it's safe not to reload?

Try calling setOnlyReadsMemory() and setDoesNotThrow() on the Function object when you create it.

- Chuck

THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all computers.