[llvm-commits] [llvm] InstCombiner::visitStoreInst() about bitfield access
Jin Gu Kang
jaykang10 at imrc.kist.re.kr
Thu Mar 10 22:40:47 PST 2011
Hi all
I found a case where some of instructions generated by
bitfield access can be removed.
For example,
-------------------------------------------------------------
test c source code
-------------------------------------------------------------
struct test {
int low:4;
int high:4;
char ch;
};
int main()
{
struct test u;
u.low=0x5;
printf("%d", u.low);
return 0;
}
-------------------------------------------------------------
bitcode after InstCombine
-------------------------------------------------------------
%struct.test = type { i8, i8, [2 x i8] }
@.str = private unnamed_addr constant [3 x i8] c"%d\00", align 4
define i32 @main() nounwind {
entry:
%retval = alloca i32, align 4
%u = alloca %struct.test, align 4
%0 = getelementptr inbounds %struct.test* %u, i32 0, i32 0
%1 = load i8* %0, align 4
%2 = and i8 %1, -16
%3 = or i8 %2, 5
store i8 %3, i8* %0, align 4
%4 = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([3 x i8]* @.str, i32 0, i32 0), i32 5) nounwind
store i32 0, i32* %retval, align 4
br label %return
return: ; preds = %entry
%retval1 = load i32* %retval, align 4
ret i32 %retval1
}
-------------------------------------------------------------
I think the following instructions are useless on above bitcode.
%u = alloca %struct.test, align 4
%0 = getelementptr inbounds %struct.test* %u, i32 0, i32 0
%1 = load i8* %0, align 4
%2 = and i8 %1, -16
%3 = or i8 %2, 5
store i8 %3, i8* %0, align 4
In case of normal filed access, current visitStoreInst() function removes
useless instructions well.
I made a patch to remove useless instructions in case of bitfield access.
Please review the attached patch.
Thanks,
Jin-Gu Kang
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20110311/c1db81d2/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: InstCombine.patch
Type: application/octet-stream
Size: 1242 bytes
Desc: InstCombine.patch
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20110311/c1db81d2/attachment.obj>
More information about the llvm-commits
mailing list