1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-21 03:53:04 +02:00
llvm-mirror/test/Transforms/PreISelIntrinsicLowering/load-relative.ll
Peter Collingbourne d04766ba20 Introduce llvm.load.relative intrinsic.
This intrinsic takes two arguments, ``%ptr`` and ``%offset``. It loads
a 32-bit value from the address ``%ptr + %offset``, adds ``%ptr`` to that
value and returns it. The constant folder specifically recognizes the form of
this intrinsic and the constant initializers it may load from; if a loaded
constant initializer is known to have the form ``i32 trunc(x - %ptr)``,
the intrinsic call is folded to ``x``.

LLVM provides that the calculation of such a constant initializer will
not overflow at link time under the medium code model if ``x`` is an
``unnamed_addr`` function. However, it does not provide this guarantee for
a constant initializer folded into a function body. This intrinsic can be
used to avoid the possibility of overflows when loading from such a constant.

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

llvm-svn: 267223
2016-04-22 21:18:02 +00:00

27 lines
1023 B
LLVM

; RUN: opt -pre-isel-intrinsic-lowering -S -o - %s | FileCheck %s
; CHECK: define i8* @foo32(i8* [[P:%.*]], i32 [[O:%.*]])
define i8* @foo32(i8* %p, i32 %o) {
; CHECK: [[OP:%.*]] = getelementptr i8, i8* [[P]], i32 [[O]]
; CHECK: [[OPI32:%.*]] = bitcast i8* [[OP]] to i32*
; CHECK: [[OI32:%.*]] = load i32, i32* [[OPI32]], align 4
; CHECK: [[R:%.*]] = getelementptr i8, i8* [[P]], i32 [[OI32]]
; CHECK: ret i8* [[R]]
%l = call i8* @llvm.load.relative.i32(i8* %p, i32 %o)
ret i8* %l
}
; CHECK: define i8* @foo64(i8* [[P:%.*]], i64 [[O:%.*]])
define i8* @foo64(i8* %p, i64 %o) {
; CHECK: [[OP:%.*]] = getelementptr i8, i8* [[P]], i64 [[O]]
; CHECK: [[OPI32:%.*]] = bitcast i8* [[OP]] to i32*
; CHECK: [[OI32:%.*]] = load i32, i32* [[OPI32]], align 4
; CHECK: [[R:%.*]] = getelementptr i8, i8* [[P]], i32 [[OI32]]
; CHECK: ret i8* [[R]]
%l = call i8* @llvm.load.relative.i64(i8* %p, i64 %o)
ret i8* %l
}
declare i8* @llvm.load.relative.i32(i8*, i32)
declare i8* @llvm.load.relative.i64(i8*, i64)