From 5000ba8961bf9c74c2e5b6ef49874d7a54aef5c6 Mon Sep 17 00:00:00 2001 From: Jin-Gu Kang Date: Sun, 13 Mar 2011 14:05:51 +0000 Subject: [PATCH] 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-svn: 127565 --- .../InstCombine/InstCombineLoadStoreAlloca.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp b/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp index f233ca6af1d..e5ff00fc1dc 100644 --- a/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp +++ b/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp @@ -433,6 +433,18 @@ Instruction *InstCombiner::visitStoreInst(StoreInst &SI) { !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(Ptr)) { if (isa(GEP->getOperand(0))) {