Quuxplusone / LLVMBugzillaTest

0 stars 0 forks source link

alias analysis misled by pointer comparison #11637

Open Quuxplusone opened 12 years ago

Quuxplusone commented 12 years ago
Bugzilla Link PR11471
Status NEW
Importance P enhancement
Reported by Richard Smith (richard-llvm@metafoo.co.uk)
Reported on 2011-12-02 21:59:42 -0800
Last modified on 2019-05-20 10:24:12 -0700
Version trunk
Hardware PC Linux
CC efriedma@quicinc.com, geek4civic@gmail.com, jryans@gmail.com, llvm-bugs@lists.llvm.org, nicholas@mxc.ca, rafael@espindo.la
Fixed by commit(s)
Attachments
Blocks
Blocked by
See also
Consider the following:

; ModuleID = '<stdin>'
target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-
f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

%struct.bar = type { i8, double, double, double }

define void @_Z1fP3bar(%struct.bar* noalias sret %agg.result, %struct.bar* %p)
nounwind uwtable {
entry:
  %ok.i = getelementptr inbounds %struct.bar* %agg.result, i64 0, i32 0
  store i8 1, i8* %ok.i, align 1, !tbaa !0
  %cmp.i = icmp eq %struct.bar* %agg.result, %p
  br i1 %cmp.i, label %if.then.i, label %_ZN3barC2EPS_.exit

if.then.i:                                        ; preds = %entry
  %ok2.i = getelementptr inbounds %struct.bar* %p, i64 0, i32 0
  store i8 0, i8* %ok2.i, align 1, !tbaa !0
  %0 = load i8* %ok.i, align 1, !tbaa !0
  %1 = and i8 %0, 1
  %tobool.i = icmp eq i8 %1, 0
  br i1 %tobool.i, label %if.then4.i, label %_ZN3barC2EPS_.exit

if.then4.i:                                       ; preds = %if.then.i
  store i8 1, i8* %ok.i, align 1, !tbaa !0
  br label %_ZN3barC2EPS_.exit

_ZN3barC2EPS_.exit:                               ; preds = %if.then4.i,
%if.then.i, %entry
  ret void
}

!0 = metadata !{metadata !"bool", metadata !1}
!1 = metadata !{metadata !"omnipotent char", metadata !2}
!2 = metadata !{metadata !"Simple C/C++ TBAA", null}

We do not optimize this any further, apparently because the icmp of %agg.result
and %p is causing us to lose the knowledge that those two pointers don't alias.
Quuxplusone commented 12 years ago

In general, it is possible to derive the value of a pointer and synthesize an pointer which aliases it using purely pointer comparisons. That said, we be more aggressive for the given testcase.