<div dir="ltr">Please consider the following C code:<div><font face="monospace"><b>    #define SZ 2048<br>    int main(void) {<br>      int A[SZ];<br>      int B[SZ];<br>      int i, tmp;<br>      for (i = 0; i < SZ; i++) {<br>        tmp = A[i];<br>        B[i] = tmp;<br>      }<br>      assert(A[SZ/2] == B[SZ/2]);<br>    }</b></font><br></div><div><br></div><div>On running -O1 followed by -reg2mem I get the following IR:</div><div><font face="monospace"><b>define dso_local i32 @main() local_unnamed_addr #0 {<br>entry:<br>  %A = alloca [2048 x i32], align 16<br>  %B = alloca [2048 x i32], align 16<br>  %"reg2mem alloca point" = bitcast i32 0 to i32<br>  %arrayidx3 = getelementptr inbounds [2048 x i32], [2048 x i32]* %A, i64 0, i64 1024<br>  %0 = load i32, i32* %arrayidx3, align 16<br>  %arrayidx4 = getelementptr inbounds [2048 x i32], [2048 x i32]* %B, i64 0, i64 1024<br>  %1 = load i32, i32* %arrayidx4, align 16<br>  %cmp5 = icmp eq i32 %0, %1<br>  %conv = zext i1 %cmp5 to i32<br>  %call = call i32 (i32, ...) bitcast (i32 (...)* @assert to i32 (i32, ...)*)(i32 %conv) #2<br>  ret i32 0<br>}</b></font><br></div><div><font face="monospace"><b><br></b></font></div><div>It is my understanding that in the original C code the assert would never fail, however in the optimized IR the assert might fail.</div><div>I tried using clang to generate the executable, and the assert doesn't fail when using -O1 but fails with -O2 and -O3 in my setting. I also tried GCC and could not get it to hit an assert fail.</div><div>Please help me in understanding the above transformation and its legality.</div><div><br></div><div>Thanks,</div><div>Akash.</div><div><br></div></div>