[llvm-dev] [canonicalization] GEP 0, 0

Piotr Padlewski via llvm-dev llvm-dev at lists.llvm.org
Fri Dec 23 08:12:10 PST 2016


Hi everyone,

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.
If I understand it correctly getelementptr with zeros is just bitcast. Is
there any good reason why it is not canonicalized into bitcast?

Example:

define void @_Z5testGv() local_unnamed_addr #0 {
entry:
 * %a* = alloca %struct.A, align 8
  %0 = bitcast %struct.A* %a to i8*
  call void @llvm.lifetime.start(i64 8, i8* nonnull %0) #3
 * %1* = getelementptr inbounds %struct.A, %struct.A* %a, i64 0, i32 0
  store i32 (...)** bitcast (i8** getelementptr inbounds ({ [3 x i8*] }, {
[3 x i8*] }* @_ZTV1A, i64 0, inrange i32 0, i64 2) to i32 (...)**), i32
(...)*** *%1*, align 8, !tbaa !8, !invariant.group !10
  call void @_Z1zR1A(%struct.A* nonnull dereferenceable(8) %a) #3
  %2 = load i32, i32* @glob, align 4, !tbaa !4
  %tobool.i = icmp eq i32 %2, 0
  br i1 %tobool.i, label %_Z1gR1A.exit, label %if.then.i

if.then.i:                                        ; preds = %entry
 * %3* = bitcast %struct.A* *%a* to void (%struct.A*)***
  %vtable.i = load void (%struct.A*)**, void (%struct.A*)*** *%3*, align 8,
!tbaa !8, !invariant.group !10
  %4 = load void (%struct.A*)*, void (%struct.A*)** %vtable.i, align 8,
!invariant.load !11
  call void %4(%struct.A* nonnull %a) #3
  br label %_Z1gR1A.exit

_Z1gR1A.exit:                                     ; preds = %entry,
%if.then.i
  call void @llvm.lifetime.end(i64 8, i8* nonnull %0) #3
  ret void
}


I can easily fix it in MemDep here
https://github.com/llvm-mirror/llvm/blob/master/lib/Analysis/MemoryDependenceAnalysis.cpp#L361
by adding gep with zeros, but it sounds like a canonicalization problem for
me.

Piotr
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20161223/d7a08d38/attachment.html>


More information about the llvm-dev mailing list