[llvm-commits] [llvm] InstCombiner::visitStoreInst() about bitfield access

Jin Gu Kang jaykang10 at imrc.kist.re.kr
Fri Mar 11 14:59:51 PST 2011


Hi all

Is it all right to commit this patch?

Thanks,
Jin-Gu Kang
________________________________
From: llvm-commits-bounces at cs.uiuc.edu [llvm-commits-bounces at cs.uiuc.edu] On Behalf Of Jin Gu Kang [jaykang10 at imrc.kist.re.kr]
Sent: Friday, March 11, 2011 3:40 PM
To: llvm-commits at cs.uiuc.edu
Subject: [llvm-commits] [llvm] InstCombiner::visitStoreInst() about bitfield access

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/20110312/6bdde589/attachment.html>


More information about the llvm-commits mailing list