1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2025-01-31 20:51:52 +01:00
llvm-mirror/test/Transforms/ObjCARC/contract-replace-arg-use.ll
Akira Hatanaka ca4f080a72 [ObjCARC] Do not turn a call to @objc_autoreleaseReturnValue into a call
to @objc_autorelease if its operand is a PHI and the PHI has an
equivalent value that is used by a return instruction.

For example, ARC optimizer shouldn't replace the call in the following
example, as doing so breaks the AutoreleaseRV/RetainRV optimization:

  %v1 = bitcast i32* %v0 to i8*
  br label %bb3
bb2:
  %v3 = bitcast i32* %v2 to i8*
  br label %bb3
bb3:
  %p = phi i8* [ %v1, %bb1 ], [ %v3, %bb2 ]
  %retval = phi i32* [ %v0, %bb1 ], [ %v2, %bb2 ] ; equivalent to %p
  %v4 = tail call i8* @objc_autoreleaseReturnValue(i8* %p)
  ret i32* %retval

Also, make sure ObjCARCContract replaces @objc_autoreleaseReturnValue's
operand uses with its value so that the call gets tail-called.

rdar://problem/15894705

llvm-svn: 323009
2018-01-19 23:51:13 +00:00

47 lines
1.4 KiB
LLVM

; RUN: opt -objc-arc-contract -S < %s | FileCheck %s
declare i8* @objc_autoreleaseReturnValue(i8*)
declare i8* @foo1()
; Check that ARC contraction replaces the function return with the value
; returned by @objc_autoreleaseReturnValue.
; CHECK-LABEL: define i32* @autoreleaseRVTailCall(
; CHECK: %[[V0:[0-9]+]] = tail call i8* @objc_autoreleaseReturnValue(
; CHECK: %[[V1:[0-9]+]] = bitcast i8* %[[V0]] to i32*
; CHECK: ret i32* %[[V1]]
define i32* @autoreleaseRVTailCall() {
%1 = call i8* @foo1()
%2 = bitcast i8* %1 to i32*
%3 = tail call i8* @objc_autoreleaseReturnValue(i8* %1)
ret i32* %2
}
declare i32* @foo2(i32);
; CHECK-LABEL: define i32* @autoreleaseRVTailCallPhi(
; CHECK: %[[PHIVAL:.*]] = phi i8* [ %{{.*}}, %bb1 ], [ %{{.*}}, %bb2 ]
; CHECK: %[[RETVAL:.*]] = phi i32* [ %{{.*}}, %bb1 ], [ %{{.*}}, %bb2 ]
; CHECK: %[[V4:.*]] = tail call i8* @objc_autoreleaseReturnValue(i8* %[[PHIVAL]])
; CHECK: %[[V0:.*]] = bitcast i8* %[[V4]] to i32*
; CHECK: ret i32* %[[V0]]
define i32* @autoreleaseRVTailCallPhi(i1 %cond) {
entry:
br i1 %cond, label %bb1, label %bb2
bb1:
%v0 = call i32* @foo2(i32 1)
%v1 = bitcast i32* %v0 to i8*
br label %bb3
bb2:
%v2 = call i32* @foo2(i32 2)
%v3 = bitcast i32* %v2 to i8*
br label %bb3
bb3:
%phival = phi i8* [ %v1, %bb1 ], [ %v3, %bb2 ]
%retval = phi i32* [ %v0, %bb1 ], [ %v2, %bb2 ]
%v4 = tail call i8* @objc_autoreleaseReturnValue(i8* %phival)
ret i32* %retval
}