1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-22 04:22:57 +02:00
llvm-mirror/test/Analysis/ValueTracking/deref-bitcast-of-gep.ll
Sanjoy Das 1a00547e1a Reduce dependence on pointee types when deducing dereferenceability
Summary:
Change some of the internal interfaces in Loads.cpp to keep track of the
number of bytes we're trying to prove dereferenceable using an explicit
`Size` parameter.

Before this, the `Size` parameter was implicitly inferred from the
pointee type of the pointer whose dereferenceability we were trying to
prove, causing us to be conservative around bitcasts. This was
unfortunate since bitcast instructions are no-ops and should never
break optimizations.  With an explicit `Size` parameter, we're more
precise (as shown in the test cases), and the code is simpler.

We should eventually move towards a `DerefQuery` struct that groups
together a base pointer, an offset, a size and an alignment; but this
patch is a first step.

Reviewers: apilipenko, dblaikie, hfinkel, reames

Subscribers: mcrosier, llvm-commits

Differential Revision: http://reviews.llvm.org/D20764

llvm-svn: 271406
2016-06-01 16:47:45 +00:00

83 lines
2.1 KiB
LLVM

; RUN: opt -S -licm < %s | FileCheck %s
; Note: the !invariant.load is there just solely to let us call @use()
; to add a fake use, and still have the aliasing work out. The call
; to @use(0) is just to provide a may-unwind exit out of the loop, so
; that LICM cannot hoist out the load simply because it is guaranteed
; to execute.
declare void @use(i32)
define void @f_0(i8* align 4 dereferenceable(1024) %ptr) {
; CHECK-LABEL: @f_0(
; CHECK: entry:
; CHECK: %val = load i32, i32* %ptr.i32
; CHECK: br label %loop
; CHECK: loop:
; CHECK: call void @use(i32 0)
; CHECK-NEXT: call void @use(i32 %val)
entry:
%ptr.gep = getelementptr i8, i8* %ptr, i32 32
%ptr.i32 = bitcast i8* %ptr.gep to i32*
br label %loop
loop:
call void @use(i32 0)
%val = load i32, i32* %ptr.i32, !invariant.load !{}
call void @use(i32 %val)
br label %loop
}
define void @f_1(i8* align 4 dereferenceable_or_null(1024) %ptr) {
; CHECK-LABEL: @f_1(
entry:
%ptr.gep = getelementptr i8, i8* %ptr, i32 32
%ptr.i32 = bitcast i8* %ptr.gep to i32*
%ptr_is_null = icmp eq i8* %ptr, null
br i1 %ptr_is_null, label %leave, label %loop
; CHECK: loop.preheader:
; CHECK: %val = load i32, i32* %ptr.i32
; CHECK: br label %loop
; CHECK: loop:
; CHECK: call void @use(i32 0)
; CHECK-NEXT: call void @use(i32 %val)
loop:
call void @use(i32 0)
%val = load i32, i32* %ptr.i32, !invariant.load !{}
call void @use(i32 %val)
br label %loop
leave:
ret void
}
define void @f_2(i8* align 4 dereferenceable_or_null(1024) %ptr) {
; CHECK-LABEL: @f_2(
; CHECK-NOT: load
; CHECK: call void @use(i32 0)
; CHECK-NEXT: %val = load i32, i32* %ptr.i32, !invariant.load !0
; CHECK-NEXT: call void @use(i32 %val)
entry:
;; Can't hoist, since the alignment does not work out -- (<4 byte
;; aligned> + 30) is not necessarily 4 byte aligned.
%ptr.gep = getelementptr i8, i8* %ptr, i32 30
%ptr.i32 = bitcast i8* %ptr.gep to i32*
%ptr_is_null = icmp eq i8* %ptr, null
br i1 %ptr_is_null, label %leave, label %loop
loop:
call void @use(i32 0)
%val = load i32, i32* %ptr.i32, !invariant.load !{}
call void @use(i32 %val)
br label %loop
leave:
ret void
}