[LLVMdev] About user of bitcast/GEP instruction

Hal Finkel hfinkel at anl.gov
Fri Jan 30 07:34:06 PST 2015


----- Original Message -----
> From: "guoqing zhang" <gqzhang81 at gmail.com>
> To: "Hal Finkel" <hfinkel at anl.gov>
> Cc: llvmdev at cs.uiuc.edu
> Sent: Friday, January 30, 2015 9:17:13 AM
> Subject: Re: [LLVMdev] About user of bitcast/GEP instruction
> 
> 
> 
> Hi,
> 
> If the special handling in the meg2reg pass is to look for lifetime
> intrinsics, shouldn't it cast to <IntrisicInst> and then use
> getInstrinsicID to check for lifetime_start and lifetime_end ?
> 
> 
> The thing that I don't understand is the following piece of code,
> which finds all the users and cast it to <Instruction> then
> eraseFromParent(). How can this guarantee that it only erase
> lifetime instrinsics ?

I think that Chandler (cc'd) is the best person to explain the overall algorithm here. Please note, however, that this is an internal routine that has implicit preconditions. Why are you looking at it?

The comment at the top of the function says:

  // Knowing that this alloca is promotable, we know that it's safe to kill all
  // instructions except for load and store.

and so we already know that the alloca is not used in any non-trivial way except by loads or stores (or perhaps some other kinds of intrinsics). There are explicit checks for lifetime intrinsics elsewhere, and if the alloca were used by anything that returned a value (like a bitcase or a GEP) that was used by anything other than a lifetime intrinsic, then it would not be promotable and this routine should not be called.

 -Hal

> 
> 
> -guoqing
> 
> 
> 
> // The only users of this bitcast/GEP instruction are lifetime
> intrinsics.
> // Follow the use/def chain to erase them now instead of leaving it
> for
> // dead code elimination later.
> for (auto UUI = I->user_begin(), UUE = I->user_end(); UUI != UUE;) {
> Instruction *Inst = cast<Instruction>(*UUI);
> ++UUI;
> Inst->eraseFromParent();
> }
> 
> 
> On Fri, Jan 30, 2015 at 1:55 PM, Hal Finkel < hfinkel at anl.gov >
> wrote:
> 
> 
> ----- Original Message -----
> > From: "guoqing zhang" < gqzhang81 at gmail.com >
> > To: llvmdev at cs.uiuc.edu
> > Sent: Friday, January 30, 2015 4:29:16 AM
> > Subject: [LLVMdev] About user of bitcast/GEP instruction
> > 
> > Hi,
> > 
> > 
> > In PromoteMemoryToRegister.cpp, it seems to rely on the fact that
> > the
> > only users of bitcast/GEP instruction are lifetime intrinsics
> > (llvm.lifetime.start/end).
> 
> You're misreading that code. There is special handling is that pass
> for looking through those instructions to find lifetime intrinsics,
> but that's all.
> 
> > I did some searching in llvm/test folder,
> > it seems to be true.
> > 
> 
> bitcasts and GEPs are general-purpose instructions. GEPs are most
> often used by loads/stores. Look at
> test/Transforms/LoopReroll/basic.ll for an example with lots of
> them. test/Analysis/BasicAA/gep-alias.ll is another place to look.
> 
> > 
> > However, by reading LLVM IR manual, I don't see any restriction
> > stated on the possible user of bitcast/GEP instruction. So my
> > question is who impose the restriction ? Is it Clang ?
> 
> There is definitely no such restriction.
> 
> -Hal
> 
> 
> 
> > 
> > 
> > Regards
> > -guoqing
> > _______________________________________________
> > LLVM Developers mailing list
> > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu
> > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
> > 
> 
> --
> Hal Finkel
> Assistant Computational Scientist
> Leadership Computing Facility
> Argonne National Laboratory
> 
> 



More information about the llvm-dev mailing list