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

Nick Lewycky nicholas at mxc.ca
Sun Mar 13 12:20:21 PDT 2011


On 03/13/2011 07:05 AM, Jin-Gu Kang wrote:
> Author: jaykang10
> Date: Sun Mar 13 09:05:51 2011
> New Revision: 127565
>
> URL: http://llvm.org/viewvc/llvm-project?rev=127565&view=rev
> Log:
> Add comment as following:
> load and store reference same memory location, the memory location
> is represented by getelementptr with two uses (load and store) and
> the getelementptr's base is alloca with single use. At this point,
> instructions from alloca to store can be removed.
> (this pattern is generated when bitfield is accessed.)
> For example,
> %u = alloca %struct.test, align 4               ; [#uses=1]
> %0 = getelementptr inbounds %struct.test* %u, i32 0, i32 0;[#uses=2]
> %1 = load i8* %0, align 4                       ; [#uses=1]
> %2 = and i8 %1, -16                             ; [#uses=1]
> %3 = or i8 %2, 5                                ; [#uses=1]
> store i8 %3, i8* %0, align 4

LLVM already optimizes this with opt -O2. Why does it need to be in 
instcombine?

Nick

>
> Modified:
>      llvm/trunk/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
>
> Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp?rev=127565&r1=127564&r2=127565&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp (original)
> +++ llvm/trunk/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp Sun Mar 13 09:05:51 2011
> @@ -433,6 +433,18 @@
>             !SI.isVolatile()) {
>           if (LI == Val)
>             return EraseInstFromFunction(SI);
> +        // load and store reference same memory location, the memory location
> +        // is represented by getelementptr with two uses (load and store) and
> +        // the getelementptr's base is alloca with single use. At this point,
> +        // instructions from alloca to store can be removed.
> +        // (this pattern is generated when bitfield is accessed.)
> +        // For example,
> +        // %u = alloca %struct.test, align 4               ; [#uses=1]
> +        // %0 = getelementptr inbounds %struct.test* %u, i32 0, i32 0;[#uses=2]
> +        // %1 = load i8* %0, align 4                       ; [#uses=1]
> +        // %2 = and i8 %1, -16                             ; [#uses=1]
> +        // %3 = or i8 %2, 5                                ; [#uses=1]
> +        // store i8 %3, i8* %0, align 4
>           if (Ptr->hasNUses(2)) {
>             if (GetElementPtrInst *GEP = dyn_cast<GetElementPtrInst>(Ptr)) {
>               if (isa<AllocaInst>(GEP->getOperand(0))) {
>
>
> _______________________________________________
> 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