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

Jin Gu Kang jaykang10 at imrc.kist.re.kr
Sat Mar 12 06:10:27 PST 2011


Hi Duncan

I sended testcase on previous e-mail as following:

>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.
 
and 

>   %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

"%Ptr2 = bitcast i32 *%Ptr, i32*" instruction is removed on InstCombine Pass
so equivalentAddressValues does not check this instrucion.

Thanks your comment,
Jin-Gu Kang



More information about the llvm-commits mailing list