<div dir="ltr">Hi everyone,<div><br></div><div>I started digging into MemDep to enhance devirtualization and I found out that it doesn't handle invariant.group if it will find GEP 0, 0.</div><div>If I understand it correctly getelementptr with zeros is just bitcast. Is there any good reason why it is not canonicalized into bitcast?</div><div><br></div><div>Example:</div><div><br></div><div><div>define void @_Z5testGv() local_unnamed_addr #0 {</div><div>entry:</div><div> <b> %a</b> = alloca %struct.A, align 8</div><div>  %0 = bitcast %struct.A* %a to i8*</div><div>  call void @llvm.lifetime.start(i64 8, i8* nonnull %0) #3</div><div> <b> %1</b> = getelementptr inbounds %struct.A, %struct.A* %a, i64 0, i32 0</div><div>  store i32 (...)** bitcast (i8** getelementptr inbounds ({ [3 x i8*] }, { [3 x i8*] }* @_ZTV1A, i64 0, inrange i32 0, i64 2) to i32 (...)**), i32 (...)*** <b>%1</b>, align 8, !tbaa !8, !invariant.group !10</div><div>  call void @_Z1zR1A(%struct.A* nonnull dereferenceable(8) %a) #3</div><div>  %2 = load i32, i32* @glob, align 4, !tbaa !4</div><div>  %tobool.i = icmp eq i32 %2, 0</div><div>  br i1 %tobool.i, label %_Z1gR1A.exit, label %if.then.i</div><div><br></div><div>if.then.i:                                        ; preds = %entry</div><div> <b> %3</b> = bitcast %struct.A* <b>%a</b> to void (%struct.A*)***</div><div>  %vtable.i = load void (%struct.A*)**, void (%struct.A*)*** <b>%3</b>, align 8, !tbaa !8, !invariant.group !10</div><div>  %4 = load void (%struct.A*)*, void (%struct.A*)** %vtable.i, align 8, !invariant.load !11</div><div>  call void %4(%struct.A* nonnull %a) #3</div><div>  br label %_Z1gR1A.exit</div><div><br></div><div>_Z1gR1A.exit:                                     ; preds = %entry, %if.then.i</div><div>  call void @llvm.lifetime.end(i64 8, i8* nonnull %0) #3</div><div>  ret void</div><div>}</div></div><div><br></div><div><br></div><div>I can easily fix it in MemDep here <a href="https://github.com/llvm-mirror/llvm/blob/master/lib/Analysis/MemoryDependenceAnalysis.cpp#L361">https://github.com/llvm-mirror/llvm/blob/master/lib/Analysis/MemoryDependenceAnalysis.cpp#L361</a> by adding gep with zeros, but it sounds like a canonicalization problem for me.</div><div><br></div><div>Piotr</div></div>