[llvm-commits] [llvm] r127539 - /llvm/trunk/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp

Duncan Sands baldrick at free.fr
Sat Mar 12 05:28:47 PST 2011


Hi Jin-Gu,

> This patch removes some of useless instructions generated by bitfield access.

please add a testcase.

> +        if (Ptr->hasNUses(2)) {

I'm not sure that this test is adequate.  Consider the following possibility:
   %A = alloca i32
   %Ptr = getelementptr A, 0
   %Ptr2 = bitcast i32 *%Ptr, i32*
   %LI = load %Ptr2
   do other stuff with Ptr2 that modifies the contents of %A
   %ST = store %LI, %Ptr <-- would be wrong to remove the store

Observe that %Ptr has only two uses (the store %SI and %Ptr2) which is
what you check for, however %Ptr2 may have many uses so in effect %Ptr has
many uses.  Maybe this is not the best example because equivalentAddressValues
will not understand that %Ptr and %Ptr2 are equivalent addresses, but of course
they are equivalent so what if equivalentAddressValues was improved to detect
this case as equivalent in the future?

Also, please add some comments explaining what you are doing.

Ciao, Duncan.

   call void @something(Ptr2)
> +          if (GetElementPtrInst *GEP = dyn_cast<GetElementPtrInst>(Ptr)) {
> +            if (isa<AllocaInst>(GEP->getOperand(0))) {
> +              if (GEP->getOperand(0)->hasOneUse())
> +                return EraseInstFromFunction(SI);
> +            }
> +          }
> +        }
> +      }
>
>         // Otherwise, this is a load from some other location.  Stores before it
>         // may not be dead.
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits




More information about the llvm-commits mailing list