<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
</head>
<body bgcolor="#ffffff" text="#000000">
I am studying the Transform/Scalar/LICM.cpp pass, and wrote a simple
test program to validate.<br>
<br>
void testLICM(void){<br>
int i,N=100;<br>
int data;<br>
for(i=0;i<N;i++){<br>
<font color="#ff0000"> data = 1;</font><br>
printf("i: %d\n",i);<br>
}<br>
printf("data: %d\n", data);<br>
}<br>
<br>
<br>
I expect the "data=1" will be moved out of loop (either hoist or
sink).<br>
However, to my surprise, that statement remains within the loop
after -licm.<br>
<br>
This is the licm produced IR:<br>
<br>
define void @testLICM() nounwind {<br>
entry:<br>
%i = alloca i32 ; <i32*>
[#uses=3]<br>
%N = alloca i32 ; <i32*>
[#uses=2]<br>
%data = alloca i32 ; <i32*>
[#uses=2]<br>
%"alloca point" = bitcast i32 0 to i32 ; <i32>
[#uses=0]<br>
call void @llvm.dbg.declare(metadata !{i32* %i}, metadata !0),
!dbg !7<br>
call void @llvm.dbg.declare(metadata !{i32* %N}, metadata !8),
!dbg !7<br>
call void @llvm.dbg.declare(metadata !{i32* %data}, metadata !9),
!dbg !7<br>
store i32 100, i32* %N, align 4, !dbg !10<br>
store i32 0, i32* %i, align 4, !dbg !11<br>
%0 = load i32* %N, align 4, !dbg !11 ; <i32>
[#uses=1]<br>
%i.promoted = load i32* %i ; <i32>
[#uses=1]<br>
br label %bb1, !dbg !11<br>
<br>
bb: ; preds = %bb1<br>
<font color="#ff0000"> store i32 1, i32* %data, align 4, !dbg !12<br>
</font> %1 = call i32 (i8*, ...)* @printf(i8* noalias getelementptr
inbounds ([7 x i8]* @.str, i32 0, i32 0), i32 %i.tmp.0) nounwind,
!dbg !13 ; <i32> [#uses=0]<br>
%2 = add nsw i32 %i.tmp.0, 1, !dbg !11 ; <i32>
[#uses=1]<br>
br label %bb1, !dbg !11<br>
<br>
bb1: ; preds = %bb,
%entry<br>
%i.tmp.0 = phi i32 [ %i.promoted, %entry ], [ %2, %bb ] ;
<i32> [#uses=4]<br>
%3 = icmp slt i32 %i.tmp.0, %0, !dbg !11 ; <i1>
[#uses=1]<br>
br i1 %3, label %bb, label %bb2, !dbg !11<br>
<br>
bb2: ; preds = %bb1<br>
store i32 %i.tmp.0, i32* %i<br>
%4 = load i32* %data, align 4, !dbg !14 ; <i32>
[#uses=1]<br>
%5 = call i32 (i8*, ...)* @printf(i8* noalias getelementptr
inbounds ([10 x i8]* @.str1, i32 0, i32 0), i32 %4) nounwind, !dbg
!14 ; <i32> [#uses=0]<br>
br label %return, !dbg !15<br>
<br>
return: ; preds = %bb2<br>
ret void, !dbg !15<br>
}<br>
<br>
<br>
I ran the program with licm only option through opt:<br>
opt -licm < test.bc > test.licm.bc<br>
<br>
<br>
Is this a bug, or am I running it in a wrong way?<br>
<br>
Thank you<br>
<br>
Chuck<br>
<br>
</body>
</html>