mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-26 04:32:44 +01:00
28ca22b845
The D82085 "allow TRE for non-capturing calls" caused failure during bootstrap. This patch does the same as D82085 plus fixes bootstrap error. The problem with D82085 is that it does not create copies for byval operands, while replacing function call with a branch. Consider following example: ``` int zoo ( S p1 ); int foo ( int count, S p1 ) { if ( count > 10 ) return zoo(p1); // temporarily variable created for passing byvalue parameter // p1 could be used when zoo(p1) is called(after TRE is done). // lifetime.start p1.byvalue.temp return foo(count+1, p1); // lifetime.end p1.byvalue.temp } ``` After recursive call to foo is replaced with a jump into start of the function, its parameters could be passed to zoo function. i.e. temporarily variable created for byvalue parameter "p1" could be passed to zoo. Finally zoo receives broken operand: ``` int foo ( int count, S p1 ) { :tailrecurse p1_tr = phi p1, p1.byvalue.temp if ( count > 10 ) return zoo(p1_tr); // temporarily variable created for passing byvalue parameter // p1 could be used when zoo(p1) is called(after TRE is done). lifetime.start p1.byvalue.temp memcpy (p1.byvalue.temp, p1_tr) count = count + 1 lifetime.end p1.byvalue.temp br tailrecurse } ``` To prevent using p1.byvalue.temp after its scope finished by lifetime.end marker this patch copies value from p1.byvalue.temp into another temporarily variable and then copies this variable into the input parameter for next iteration. This patch passes bootstrap build and bootstrap build with AddressSanitizer. Differential Revision: https://reviews.llvm.org/D85614
145 lines
8.1 KiB
LLVM
145 lines
8.1 KiB
LLVM
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
|
|
; RUN: opt < %s -tailcallelim -verify-dom-info -S | FileCheck %s
|
|
|
|
; the test was generated from the following C++ source:
|
|
;
|
|
; #include <stdio.h>
|
|
; typedef struct A { long long x[10] = {0}; } A;
|
|
; A global;
|
|
; void dostuff(A a, A b, int i) {
|
|
; if (i==10) return;
|
|
; a.x[5]++;
|
|
; printf("%lld %lld\n", a.x[5], b.x[5]); dostuff(b, a, i+1);
|
|
; }
|
|
; __attribute((optnone)) int main() { dostuff(global, global, 0); }
|
|
;
|
|
; This test checks that values for two ByValue operands are copied
|
|
; into temporarily variables first and then the temporaily
|
|
; variables are copied into original function arguments location.
|
|
|
|
%struct.A = type { [10 x i64] }
|
|
|
|
@global = dso_local local_unnamed_addr global %struct.A zeroinitializer, align 8
|
|
@.str = private unnamed_addr constant [11 x i8] c"%lld %lld\0A\00", align 1
|
|
|
|
; Function Attrs: noinline nounwind uwtable
|
|
define dso_local void @_Z7dostuff1AS_i(%struct.A* nocapture byval(%struct.A) align 8 %a, %struct.A* nocapture readonly byval(%struct.A) align 8 %b, i32 %i) local_unnamed_addr #0 {
|
|
; CHECK-LABEL: @_Z7dostuff1AS_i(
|
|
; CHECK-NEXT: entry:
|
|
; CHECK-NEXT: [[AGG_TMP52:%.*]] = alloca [[STRUCT_A:%.*]], align 8
|
|
; CHECK-NEXT: [[AGG_TMP1:%.*]] = alloca [[STRUCT_A]], align 8
|
|
; CHECK-NEXT: [[AGG_TMP:%.*]] = alloca [[STRUCT_A]], align 8
|
|
; CHECK-NEXT: [[AGG_TMP5:%.*]] = alloca [[STRUCT_A]], align 8
|
|
; CHECK-NEXT: br label [[TAILRECURSE:%.*]]
|
|
; CHECK: tailrecurse:
|
|
; CHECK-NEXT: [[I_TR:%.*]] = phi i32 [ [[I:%.*]], [[ENTRY:%.*]] ], [ [[ADD:%.*]], [[IF_END:%.*]] ]
|
|
; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[I_TR]], 10
|
|
; CHECK-NEXT: br i1 [[CMP]], label [[RETURN:%.*]], label [[IF_END]]
|
|
; CHECK: if.end:
|
|
; CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds [[STRUCT_A]], %struct.A* [[A:%.*]], i64 0, i32 0, i64 5
|
|
; CHECK-NEXT: [[TMP0:%.*]] = load i64, i64* [[ARRAYIDX]], align 8
|
|
; CHECK-NEXT: [[INC:%.*]] = add nsw i64 [[TMP0]], 1
|
|
; CHECK-NEXT: store i64 [[INC]], i64* [[ARRAYIDX]], align 8
|
|
; CHECK-NEXT: [[ARRAYIDX4:%.*]] = getelementptr inbounds [[STRUCT_A]], %struct.A* [[B:%.*]], i64 0, i32 0, i64 5
|
|
; CHECK-NEXT: [[TMP1:%.*]] = load i64, i64* [[ARRAYIDX4]], align 8
|
|
; CHECK-NEXT: [[CALL:%.*]] = tail call i32 (i8*, ...) @printf(i8* nonnull dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i64 [[INC]], i64 [[TMP1]])
|
|
; CHECK-NEXT: [[TMP2:%.*]] = bitcast %struct.A* [[AGG_TMP]] to i8*
|
|
; CHECK-NEXT: call void @llvm.lifetime.start.p0i8(i64 80, i8* nonnull [[TMP2]])
|
|
; CHECK-NEXT: [[TMP3:%.*]] = bitcast %struct.A* [[B]] to i8*
|
|
; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i64(i8* nonnull align 8 dereferenceable(80) [[TMP2]], i8* nonnull align 8 dereferenceable(80) [[TMP3]], i64 80, i1 false)
|
|
; CHECK-NEXT: [[TMP4:%.*]] = bitcast %struct.A* [[AGG_TMP5]] to i8*
|
|
; CHECK-NEXT: call void @llvm.lifetime.start.p0i8(i64 80, i8* nonnull [[TMP4]])
|
|
; CHECK-NEXT: [[TMP5:%.*]] = bitcast %struct.A* [[A]] to i8*
|
|
; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i64(i8* nonnull align 8 dereferenceable(80) [[TMP4]], i8* nonnull align 8 dereferenceable(80) [[TMP5]], i64 80, i1 false)
|
|
; CHECK-NEXT: [[ADD]] = add nsw i32 [[I_TR]], 1
|
|
; CHECK-NEXT: [[TMP6:%.*]] = bitcast %struct.A* [[AGG_TMP1]] to i8*
|
|
; CHECK-NEXT: [[TMP7:%.*]] = bitcast %struct.A* [[AGG_TMP]] to i8*
|
|
; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 8 [[TMP6]], i8* align 8 [[TMP7]], i64 80, i1 false)
|
|
; CHECK-NEXT: [[TMP8:%.*]] = bitcast %struct.A* [[AGG_TMP52]] to i8*
|
|
; CHECK-NEXT: [[TMP9:%.*]] = bitcast %struct.A* [[AGG_TMP5]] to i8*
|
|
; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 8 [[TMP8]], i8* align 8 [[TMP9]], i64 80, i1 false)
|
|
; CHECK-NEXT: [[TMP10:%.*]] = bitcast %struct.A* [[A]] to i8*
|
|
; CHECK-NEXT: [[TMP11:%.*]] = bitcast %struct.A* [[AGG_TMP1]] to i8*
|
|
; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 8 [[TMP10]], i8* align 8 [[TMP11]], i64 80, i1 false)
|
|
; CHECK-NEXT: [[TMP12:%.*]] = bitcast %struct.A* [[B]] to i8*
|
|
; CHECK-NEXT: [[TMP13:%.*]] = bitcast %struct.A* [[AGG_TMP52]] to i8*
|
|
; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 8 [[TMP12]], i8* align 8 [[TMP13]], i64 80, i1 false)
|
|
; CHECK-NEXT: call void @llvm.lifetime.end.p0i8(i64 80, i8* nonnull [[TMP2]])
|
|
; CHECK-NEXT: call void @llvm.lifetime.end.p0i8(i64 80, i8* nonnull [[TMP4]])
|
|
; CHECK-NEXT: br label [[TAILRECURSE]]
|
|
; CHECK: return:
|
|
; CHECK-NEXT: ret void
|
|
;
|
|
entry:
|
|
%agg.tmp = alloca %struct.A, align 8
|
|
%agg.tmp5 = alloca %struct.A, align 8
|
|
%cmp = icmp eq i32 %i, 10
|
|
br i1 %cmp, label %return, label %if.end
|
|
|
|
if.end: ; preds = %entry
|
|
%arrayidx = getelementptr inbounds %struct.A, %struct.A* %a, i64 0, i32 0, i64 5
|
|
%0 = load i64, i64* %arrayidx, align 8
|
|
%inc = add nsw i64 %0, 1
|
|
store i64 %inc, i64* %arrayidx, align 8
|
|
%arrayidx4 = getelementptr inbounds %struct.A, %struct.A* %b, i64 0, i32 0, i64 5
|
|
%1 = load i64, i64* %arrayidx4, align 8
|
|
%call = call i32 (i8*, ...) @printf(i8* nonnull dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str
|
|
, i64 0, i64 0), i64 %inc, i64 %1)
|
|
%2 = bitcast %struct.A* %agg.tmp to i8*
|
|
call void @llvm.lifetime.start.p0i8(i64 80, i8* nonnull %2)
|
|
%3 = bitcast %struct.A* %b to i8*
|
|
call void @llvm.memcpy.p0i8.p0i8.i64(i8* nonnull align 8 dereferenceable(80) %2, i8* nonnull align 8 dereferenceable(80) %3, i64 80, i1 false)
|
|
%4 = bitcast %struct.A* %agg.tmp5 to i8*
|
|
call void @llvm.lifetime.start.p0i8(i64 80, i8* nonnull %4)
|
|
%5 = bitcast %struct.A* %a to i8*
|
|
call void @llvm.memcpy.p0i8.p0i8.i64(i8* nonnull align 8 dereferenceable(80) %4, i8* nonnull align 8 dereferenceable(80) %5, i64 80, i1 false)
|
|
%add = add nsw i32 %i, 1
|
|
call void @_Z7dostuff1AS_i(%struct.A* nonnull byval(%struct.A) align 8 %agg.tmp, %struct.A* nonnull byval(%struct.A) align 8 %agg.tmp5, i32 %add)
|
|
call void @llvm.lifetime.end.p0i8(i64 80, i8* nonnull %2)
|
|
call void @llvm.lifetime.end.p0i8(i64 80, i8* nonnull %4)
|
|
br label %return
|
|
|
|
return: ; preds = %entry, %if.end
|
|
ret void
|
|
}
|
|
|
|
; Function Attrs: nofree nounwind
|
|
declare dso_local noundef i32 @printf(i8* nocapture noundef readonly, ...) local_unnamed_addr #1
|
|
|
|
; Function Attrs: argmemonly nounwind willreturn
|
|
declare void @llvm.memcpy.p0i8.p0i8.i64(i8* noalias nocapture writeonly, i8* noalias nocapture readonly, i64, i1 immarg) #2
|
|
|
|
; Function Attrs: argmemonly nounwind willreturn
|
|
declare void @llvm.lifetime.start.p0i8(i64 immarg, i8* nocapture) #2
|
|
|
|
; Function Attrs: argmemonly nounwind willreturn
|
|
declare void @llvm.lifetime.end.p0i8(i64 immarg, i8* nocapture) #2
|
|
|
|
; Function Attrs: noinline norecurse nounwind optnone uwtable
|
|
define dso_local i32 @main() local_unnamed_addr #3 {
|
|
; CHECK-LABEL: @main(
|
|
; CHECK-NEXT: entry:
|
|
; CHECK-NEXT: [[AGG_TMP:%.*]] = alloca [[STRUCT_A:%.*]], align 8
|
|
; CHECK-NEXT: [[AGG_TMP1:%.*]] = alloca [[STRUCT_A]], align 8
|
|
; CHECK-NEXT: [[TMP0:%.*]] = bitcast %struct.A* [[AGG_TMP]] to i8*
|
|
; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 8 [[TMP0]], i8* align 8 bitcast (%struct.A* @global to i8*), i64 80, i1 false)
|
|
; CHECK-NEXT: [[TMP1:%.*]] = bitcast %struct.A* [[AGG_TMP1]] to i8*
|
|
; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 8 [[TMP1]], i8* align 8 bitcast (%struct.A* @global to i8*), i64 80, i1 false)
|
|
; CHECK-NEXT: tail call void @_Z7dostuff1AS_i(%struct.A* byval(%struct.A) align 8 [[AGG_TMP]], %struct.A* byval(%struct.A) align 8 [[AGG_TMP1]], i32 0)
|
|
; CHECK-NEXT: ret i32 0
|
|
;
|
|
entry:
|
|
%agg.tmp = alloca %struct.A, align 8
|
|
%agg.tmp1 = alloca %struct.A, align 8
|
|
%0 = bitcast %struct.A* %agg.tmp to i8*
|
|
call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 8 %0, i8* align 8 bitcast (%struct.A* @global to i8*), i64 80, i1 false)
|
|
%1 = bitcast %struct.A* %agg.tmp1 to i8*
|
|
call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 8 %1, i8* align 8 bitcast (%struct.A* @global to i8*), i64 80, i1 false)
|
|
call void @_Z7dostuff1AS_i(%struct.A* byval(%struct.A) align 8 %agg.tmp, %struct.A* byval(%struct.A) align 8 %agg.tmp1, i32 0)
|
|
ret i32 0
|
|
}
|
|
|
|
attributes #0 = { uwtable }
|
|
attributes #1 = { uwtable }
|
|
attributes #2 = { argmemonly nounwind willreturn }
|