diff --git a/llvm/lib/IR/Function.cpp b/llvm/lib/IR/Function.cpp --- a/llvm/lib/IR/Function.cpp +++ b/llvm/lib/IR/Function.cpp @@ -1624,6 +1624,14 @@ continue; } + if (isa(FU) && isa(FU) && + llvm::all_of(FU->uses(), [](const Use &U) { + if (const CallBase *CB = dyn_cast(U.getUser())) + return CB->isCallee(&U); + return false; + })) + continue; + const auto *Call = dyn_cast(FU); if (!Call) { if (IgnoreAssumeLikeCalls) { diff --git a/llvm/lib/Transforms/IPO/GlobalOpt.cpp b/llvm/lib/Transforms/IPO/GlobalOpt.cpp --- a/llvm/lib/Transforms/IPO/GlobalOpt.cpp +++ b/llvm/lib/Transforms/IPO/GlobalOpt.cpp @@ -2137,6 +2137,16 @@ for (User *U : F->users()) { if (isa(U)) continue; + if (isa(U) && isa(U)) { + for (User *BU : U->users()) { + if (auto CB = dyn_cast(BU)) { + if (!CB) + continue; + CB->setCallingConv(CallingConv::Fast); + } + } + continue; + } cast(U)->setCallingConv(CallingConv::Fast); } } diff --git a/llvm/test/Analysis/CallGraph/ignore-bitcast-call-argument-callee.ll b/llvm/test/Analysis/CallGraph/ignore-bitcast-call-argument-callee.ll new file mode 100644 --- /dev/null +++ b/llvm/test/Analysis/CallGraph/ignore-bitcast-call-argument-callee.ll @@ -0,0 +1,30 @@ +; RUN: opt < %s -print-callgraph -disable-output 2>&1 | FileCheck %s + +; CHECK: Call graph node <><<{{.*}}>> #uses=0 +; CHECK-NEXT: CS calls function 'foo' +; CHECK-EMPTY: +; CHECK-NEXT: Call graph node for function: 'bar'<<{{.*}}>> #uses=1 +; CHECK-EMPTY: +; CHECK-NEXT: Call graph node for function: 'foo'<<{{.*}}>> #uses=1 +; CHECK-EMPTY: +; CHECK-NEXT: Call graph node for function: 'test'<<{{.*}}>> #uses=0 +; CHECK-NEXT: CS<{{.*}}> calls function 'bar' +; CHECK-NEXT: CS<{{.*}}> calls external node + +define internal i32 @foo() { +entry: + ret i32 5 +} + +define internal i32 @bar(float()* %arg) { + ret i32 5 +} + +define internal i32 @test() { + %v1 = call i32 @bar(float()* bitcast (i32()* @foo to float()*)) + %v2 = call float bitcast (i32()* @foo to float()*)() + %v3 = fptoui float %v2 to i32 + %v4 = add i32 %v1, %v3 + ret i32 %v4 +} + diff --git a/llvm/test/Analysis/CallGraph/ignore-bitcast-call-argument.ll b/llvm/test/Analysis/CallGraph/ignore-bitcast-call-argument.ll new file mode 100644 --- /dev/null +++ b/llvm/test/Analysis/CallGraph/ignore-bitcast-call-argument.ll @@ -0,0 +1,27 @@ +; RUN: opt < %s -print-callgraph -disable-output 2>&1 | FileCheck %s + +; CHECK: Call graph node <><<{{.*}}>> #uses=0 +; CHECK-NEXT: CS calls function 'foo' +; CHECK-EMPTY: +; CHECK-NEXT: Call graph node for function: 'bar'<<{{.*}}>> #uses=1 +; CHECK-EMPTY: +; CHECK-NEXT: Call graph node for function: 'foo'<<{{.*}}>> #uses=1 +; CHECK-EMPTY: +; CHECK-NEXT: Call graph node for function: 'test'<<{{.*}}>> #uses=0 +; CHECK-NEXT: CS<{{.*}}> calls function 'bar' + +define internal i32 @foo() { +entry: + ret i32 5 +} + +define internal i32 @bar(float()* %arg) { + ret i32 5 +} + +define internal i32 @test() { + %v1 = call i32 @bar(float()* bitcast (i32()* @foo to float()*)) + %v2 = add i32 %v1, 6 + ret i32 %v2 +} + diff --git a/llvm/test/Analysis/CallGraph/ignore-bitcast-callees.ll b/llvm/test/Analysis/CallGraph/ignore-bitcast-callees.ll new file mode 100644 --- /dev/null +++ b/llvm/test/Analysis/CallGraph/ignore-bitcast-callees.ll @@ -0,0 +1,23 @@ +; RUN: opt < %s -print-callgraph -disable-output 2>&1 | FileCheck %s +; CHECK: Call graph node <><<{{.*}}>> #uses=0 +; CHECK-EMPTY: +; CHECK-NEXT: Call graph node for function: 'foo'<<{{.*}}>> #uses=0 +; CHECK-EMPTY: +; CHECK-NEXT: Call graph node for function: 'test_bitcast_callees'<<{{.*}}>> #uses=0 +; CHECK-NEXT: CS<{{.*}}> calls external node +; CHECK-NEXT: CS<{{.*}}> calls external node + +define internal i32 @foo() { +entry: + ret i32 5 +} + +define internal float @test_bitcast_callees() { + %v1 = call float bitcast (i32()* @foo to float()*)() + %v2 = fadd float %v1, 1.0 + %v3 = call i8 bitcast (i32()* @foo to i8()*)() + %v4 = uitofp i8 %v3 to float + %v5 = fadd float %v2, %v4 + ret float %v5 +} + diff --git a/llvm/test/Analysis/CallGraph/ignore-bitcast-callees2.ll b/llvm/test/Analysis/CallGraph/ignore-bitcast-callees2.ll new file mode 100644 --- /dev/null +++ b/llvm/test/Analysis/CallGraph/ignore-bitcast-callees2.ll @@ -0,0 +1,26 @@ +; RUN: opt < %s -print-callgraph -disable-output 2>&1 | FileCheck %s +; CHECK: Call graph node <><<{{.*}}>> #uses=0 +; CHECK-EMPTY: +; CHECK-NEXT: Call graph node for function: 'foo'<<{{.*}}>> #uses=0 +; CHECK-EMPTY: +; CHECK-NEXT: Call graph node for function: 'test_bitcast_callees2'<<{{.*}}>> #uses=0 +; CHECK-NEXT: CS<{{.*}}> calls external node +; CHECK-NEXT: CS<{{.*}}> calls external node +; CHECK-NEXT: CS<{{.*}}> calls external node + +define internal i32 @foo() { +entry: + ret i32 5 +} + +define internal float @test_bitcast_callees2() { + %v1 = call float bitcast (i32()* @foo to float()*)() + %v2 = fadd float %v1, 1.0 + %v3 = call float bitcast (i32()* @foo to float()*)() + %v4 = fadd float %v3, %v2 + %v5 = call i8 bitcast (i32()* @foo to i8()*)() + %v6 = uitofp i8 %v5 to float + %v7 = fadd float %v4, %v6 + ret float %v7 +} + diff --git a/llvm/test/Transforms/Attributor/IPConstantProp/arg-count-mismatch.ll b/llvm/test/Transforms/Attributor/IPConstantProp/arg-count-mismatch.ll --- a/llvm/test/Transforms/Attributor/IPConstantProp/arg-count-mismatch.ll +++ b/llvm/test/Transforms/Attributor/IPConstantProp/arg-count-mismatch.ll @@ -1,8 +1,8 @@ ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --function-signature --check-attributes --check-globals ; RUN: opt -attributor -enable-new-pm=0 -attributor-manifest-internal -attributor-max-iterations-verify -attributor-annotate-decl-cs -attributor-max-iterations=1 -S < %s | FileCheck %s --check-prefixes=CHECK,NOT_CGSCC_NPM,NOT_CGSCC_OPM,NOT_TUNIT_NPM,IS__TUNIT____,IS________OPM,IS__TUNIT_OPM ; RUN: opt -aa-pipeline=basic-aa -passes=attributor -attributor-manifest-internal -attributor-max-iterations-verify -attributor-annotate-decl-cs -attributor-max-iterations=1 -S < %s | FileCheck %s --check-prefixes=CHECK,NOT_CGSCC_OPM,NOT_CGSCC_NPM,NOT_TUNIT_OPM,IS__TUNIT____,IS________NPM,IS__TUNIT_NPM -; RUN: opt -attributor-cgscc -enable-new-pm=0 -attributor-manifest-internal -attributor-annotate-decl-cs -S < %s | FileCheck %s --check-prefixes=CHECK,NOT_TUNIT_NPM,NOT_TUNIT_OPM,NOT_CGSCC_NPM,IS__CGSCC____,IS________OPM,IS__CGSCC_OPM -; RUN: opt -aa-pipeline=basic-aa -passes=attributor-cgscc -attributor-manifest-internal -attributor-annotate-decl-cs -S < %s | FileCheck %s --check-prefixes=CHECK,NOT_TUNIT_NPM,NOT_TUNIT_OPM,NOT_CGSCC_OPM,IS__CGSCC____,IS________NPM,IS__CGSCC_NPM +; RUN: opt -attributor-cgscc -enable-new-pm=0 -attributor-manifest-internal -attributor-annotate-decl-cs -S < %s | FileCheck %s --check-prefixes=CHECK,NOT_TUNIT_NPM,NOT_TUNIT_OPM,NOT_CGSCC_NPM1,IS__CGSCC____,IS________OPM,IS__CGSCC_OPM +; RUN: opt -aa-pipeline=basic-aa -passes=attributor-cgscc -attributor-manifest-internal -attributor-annotate-decl-cs -S < %s | FileCheck %s --check-prefixes=CHECK,NOT_TUNIT_NPM,NOT_TUNIT_OPM,NOT_CGSCC_OPM,AA_IS__CGSCC____,IS________NPM,IS__CGSCC_NPM ; The original C source looked like this: ; @@ -41,6 +41,11 @@ ; NOT_CGSCC_NPM-NEXT: [[CALL:%.*]] = call i16 @bar() ; NOT_CGSCC_NPM-NEXT: ret i16 [[CALL]] ; +; NOT_CGSCC_NPM1-LABEL: define {{[^@]+}}@foo +; NOT_CGSCC_NPM1-SAME: (i16 [[A:%.*]]) { +; NOT_CGSCC_NPM1-NEXT: [[CALL:%.*]] = call i16 bitcast (i16 (i16, i16)* @bar +; NOT_CGSCC_NPM1-SAME: to i16 (i16)*)(i16 %a) +; NOT_CGSCC_NPM1-NEXT: ret i16 [[CALL]] ; IS__CGSCC_NPM: Function Attrs: nofree norecurse nosync nounwind readnone willreturn ; IS__CGSCC_NPM-LABEL: define {{[^@]+}}@foo ; IS__CGSCC_NPM-SAME: (i16 [[A:%.*]]) #[[ATTR0:[0-9]+]] { @@ -56,9 +61,8 @@ ; IS__TUNIT____-SAME: () #[[ATTR0:[0-9]+]] { ; IS__TUNIT____-NEXT: ret i16 0 ; -; IS__CGSCC_OPM: Function Attrs: nofree norecurse nosync nounwind readnone willreturn ; IS__CGSCC_OPM-LABEL: define {{[^@]+}}@bar -; IS__CGSCC_OPM-SAME: () #[[ATTR0:[0-9]+]] { +; IS__CGSCC_OPM-SAME: (i16 %p1, i16 %p2) { ; IS__CGSCC_OPM-NEXT: ret i16 0 ; ; IS__CGSCC_NPM: Function Attrs: nofree norecurse nosync nounwind readnone willreturn @@ -86,11 +90,16 @@ ; IS__TUNIT____-NEXT: [[A:%.*]] = add i16 [[P1]], [[P2]] ; IS__TUNIT____-NEXT: ret i16 [[A]] ; -; IS__CGSCC____: Function Attrs: nofree norecurse nosync nounwind readnone willreturn ; IS__CGSCC____-LABEL: define {{[^@]+}}@bar2 -; IS__CGSCC____-SAME: (i16 [[P1:%.*]], i16 [[P2:%.*]]) #[[ATTR0:[0-9]+]] { +; IS__CGSCC____-SAME: (i16 [[P1:%.*]], i16 [[P2:%.*]]) { ; IS__CGSCC____-NEXT: [[A:%.*]] = add i16 [[P1]], [[P2]] ; IS__CGSCC____-NEXT: ret i16 [[A]] + +; AA_IS__CGSCC____: Function Attrs: nofree norecurse nosync nounwind readnone willreturn +; AA_IS__CGSCC____-LABEL: define {{[^@]+}}@bar2 +; AA_IS__CGSCC____-SAME: (i16 [[P1:%.*]], i16 [[P2:%.*]]) #[[ATTR0:[0-9]+]] { +; AA_IS__CGSCC____-NEXT: [[A:%.*]] = add i16 [[P1]], [[P2]] +; AA_IS__CGSCC____-NEXT: ret i16 [[A]] ; %a = add i16 %p1, %p2 ret i16 %a @@ -103,11 +112,11 @@ ; been provided), define dso_local i16 @vararg_tests(i16 %a) { -; CHECK-LABEL: define {{[^@]+}}@vararg_tests -; CHECK-SAME: (i16 [[A:%.*]]) { -; CHECK-NEXT: [[CALL2:%.*]] = call i16 bitcast (i16 (i16, i16, ...)* @vararg_no_prop to i16 (i16)*)(i16 noundef 7) -; CHECK-NEXT: [[ADD:%.*]] = add i16 7, [[CALL2]] -; CHECK-NEXT: ret i16 [[ADD]] +; IS__CGSCC____-LABEL: define {{[^@]+}}@vararg_tests +; IS__CGSCC____-SAME: (i16 [[A:%.*]]) { +; IS__CGSCC____-NEXT: [[CALL2:%.*]] = call i16 bitcast (i16 (i16, i16, ...)* @vararg_no_prop to i16 (i16)*)(i16 7) +; IS__CGSCC____-NEXT: [[ADD:%.*]] = add i16 7, [[CALL2]] +; IS__CGSCC____-NEXT: ret i16 [[ADD]] ; %call1 = call i16 (i16, ...) @vararg_prop(i16 7, i16 8, i16 %a) %call2 = call i16 bitcast (i16 (i16, i16, ...) * @vararg_no_prop to i16 (i16) *) (i16 7) @@ -118,7 +127,7 @@ define internal i16 @vararg_prop(i16 %p1, ...) { ; IS__CGSCC____: Function Attrs: nofree norecurse nosync nounwind readnone willreturn ; IS__CGSCC____-LABEL: define {{[^@]+}}@vararg_prop -; IS__CGSCC____-SAME: (i16 returned [[P1:%.*]], ...) #[[ATTR0]] { +; IS__CGSCC____-SAME: (i16 returned [[P1:%.*]], ...) #[[ATTR0:[0-9]+]] { ; IS__CGSCC____-NEXT: ret i16 7 ; ret i16 %p1 @@ -130,10 +139,9 @@ ; IS__TUNIT____-SAME: (i16 returned [[P1:%.*]], i16 [[P2:%.*]], ...) #[[ATTR0]] { ; IS__TUNIT____-NEXT: ret i16 7 ; -; IS__CGSCC____: Function Attrs: nofree norecurse nosync nounwind readnone willreturn ; IS__CGSCC____-LABEL: define {{[^@]+}}@vararg_no_prop -; IS__CGSCC____-SAME: (i16 returned [[P1:%.*]], i16 [[P2:%.*]], ...) #[[ATTR0]] { -; IS__CGSCC____-NEXT: ret i16 7 +; IS__CGSCC____-SAME: (i16 [[P1:%.*]], i16 [[P2:%.*]], ...) { +; IS__CGSCC____-NEXT: ret i16 %p1 ; ret i16 %p1 } diff --git a/llvm/test/Transforms/Attributor/IPConstantProp/arg-type-mismatch.ll b/llvm/test/Transforms/Attributor/IPConstantProp/arg-type-mismatch.ll --- a/llvm/test/Transforms/Attributor/IPConstantProp/arg-type-mismatch.ll +++ b/llvm/test/Transforms/Attributor/IPConstantProp/arg-type-mismatch.ll @@ -2,7 +2,7 @@ ; RUN: opt -attributor -enable-new-pm=0 -attributor-manifest-internal -attributor-max-iterations-verify -attributor-annotate-decl-cs -attributor-max-iterations=1 -S < %s | FileCheck %s --check-prefixes=CHECK,NOT_CGSCC_NPM,NOT_CGSCC_OPM,NOT_TUNIT_NPM,IS__TUNIT____,IS________OPM,IS__TUNIT_OPM ; RUN: opt -aa-pipeline=basic-aa -passes=attributor -attributor-manifest-internal -attributor-max-iterations-verify -attributor-annotate-decl-cs -attributor-max-iterations=1 -S < %s | FileCheck %s --check-prefixes=CHECK,NOT_CGSCC_OPM,NOT_CGSCC_NPM,NOT_TUNIT_OPM,IS__TUNIT____,IS________NPM,IS__TUNIT_NPM ; RUN: opt -attributor-cgscc -enable-new-pm=0 -attributor-manifest-internal -attributor-annotate-decl-cs -S < %s | FileCheck %s --check-prefixes=CHECK,NOT_TUNIT_NPM,NOT_TUNIT_OPM,NOT_CGSCC_NPM,IS__CGSCC____,IS________OPM,IS__CGSCC_OPM -; RUN: opt -aa-pipeline=basic-aa -passes=attributor-cgscc -attributor-manifest-internal -attributor-annotate-decl-cs -S < %s | FileCheck %s --check-prefixes=CHECK,NOT_TUNIT_NPM,NOT_TUNIT_OPM,NOT_CGSCC_OPM,IS__CGSCC____,IS________NPM,IS__CGSCC_NPM +; RUN: opt -aa-pipeline=basic-aa -passes=attributor-cgscc -attributor-manifest-internal -attributor-annotate-decl-cs -S < %s | FileCheck %s --check-prefixes=CHECK,NOT_TUNIT_NPM,NOT_TUNIT_OPM,NOT_CGSCC_OPM,AA_IS__CGSCC____,IS________NPM,IS__CGSCC_NPM ; This test is just to verify that we do not crash/assert due to mismatch in ; argument type between the caller and callee. @@ -23,11 +23,15 @@ ; IS__TUNIT____-SAME: (i16 [[P1:%.*]], i16 returned [[P2:%.*]]) #[[ATTR0:[0-9]+]] { ; IS__TUNIT____-NEXT: ret i16 [[P2]] ; -; IS__CGSCC____: Function Attrs: nofree norecurse nosync nounwind readnone willreturn ; IS__CGSCC____-LABEL: define {{[^@]+}}@bar -; IS__CGSCC____-SAME: (i16 [[P1:%.*]], i16 returned [[P2:%.*]]) #[[ATTR0:[0-9]+]] { +; IS__CGSCC____-SAME: (i16 [[P1:%.*]], i16 [[P2:%.*]]) { ; IS__CGSCC____-NEXT: ret i16 [[P2]] ; +; AA_IS__CGSCC____: Function Attrs: nofree norecurse nosync nounwind readnone willreturn +; AA_IS__CGSCC____-LABEL: define {{[^@]+}}@bar +; AA_IS__CGSCC____-SAME: (i16 [[P1:%.*]], i16 returned [[P2:%.*]]) #[[ATTR0:[0-9]+]] { +; AA_IS__CGSCC____-NEXT: ret i16 [[P2]] +; ret i16 %p2 } @@ -35,5 +39,5 @@ ;. ; IS__TUNIT____: attributes #[[ATTR0]] = { nofree nosync nounwind readnone willreturn } ;. -; IS__CGSCC____: attributes #[[ATTR0]] = { nofree norecurse nosync nounwind readnone willreturn } +; AA_IS__CGSCC____: attributes #[[ATTR0]] = { nofree norecurse nosync nounwind readnone willreturn } ;. diff --git a/llvm/test/Transforms/GlobalOpt/bitcast-callees-fastcc.ll b/llvm/test/Transforms/GlobalOpt/bitcast-callees-fastcc.ll new file mode 100644 --- /dev/null +++ b/llvm/test/Transforms/GlobalOpt/bitcast-callees-fastcc.ll @@ -0,0 +1,18 @@ +; RUN: opt < %s -globalopt -S | FileCheck %s + +; CHECK-LABEL: define internal fastcc i32 @foo() unnamed_addr +define internal i32 @foo() { + ret i32 8 +} + +; CHECK-LABEL: define void @test_bitcast_callees2() local_unnamed_addr { +define void @test_bitcast_callees2() { + ; CHECK: %1 = call fastcc float bitcast (i32 ()* @foo to float ()*)() + call float bitcast (i32()* @foo to float()*)() + ; CHECK-NEXT: %2 = call fastcc float bitcast (i32 ()* @foo to float ()*)() + call float bitcast (i32()* @foo to float()*)() + ; CHECK-NEXT: %3 = call fastcc i8 bitcast (i32 ()* @foo to i8 ()*)() + call i8 bitcast (i32()* @foo to i8()*)() + ret void +} + diff --git a/llvm/test/Transforms/OpenMP/parallel_deletion_cg_update.ll b/llvm/test/Transforms/OpenMP/parallel_deletion_cg_update.ll --- a/llvm/test/Transforms/OpenMP/parallel_deletion_cg_update.ll +++ b/llvm/test/Transforms/OpenMP/parallel_deletion_cg_update.ll @@ -2,14 +2,13 @@ ; CHECK: Call graph node <><<{{.*}}>> #uses=0 ; CHECK: CS calls function 'dead_fork_call' -; CHECK: CS calls function '.omp_outlined..0' ; CHECK: CS calls function '__kmpc_fork_call' ; CHECK: CS calls function 'live_fork_call' ; CHECK: CS calls function '.omp_outlined..1' ; CHECK: CS calls function 'd' ; -; CHECK: Call graph node for function: '.omp_outlined..0'<<{{.*}}>> #uses=1 -; +; CHECK: Call graph node for function: '.omp_outlined..0'<<{{.*}}>> #uses=0 +; ; CHECK: Call graph node for function: '.omp_outlined..1'<<{{.*}}>> #uses=3 ; CHECK: CS<{{.*}}> calls function 'd' ; diff --git a/llvm/test/Transforms/SCCP/arg-count-mismatch.ll b/llvm/test/Transforms/SCCP/arg-count-mismatch.ll --- a/llvm/test/Transforms/SCCP/arg-count-mismatch.ll +++ b/llvm/test/Transforms/SCCP/arg-count-mismatch.ll @@ -41,7 +41,7 @@ define internal i16 @bar(i16 %p1, i16 %p2) { ; CHECK-LABEL: @bar( -; CHECK-NEXT: ret i16 0 +; CHECK-NEXT: unreachable ; ret i16 0 } @@ -73,7 +73,7 @@ define internal i16 @vararg_no_prop(i16 %p1, i16 %p2, ...) { ; CHECK-LABEL: @vararg_no_prop( -; CHECK-NEXT: ret i16 [[P1:%.*]] +; CHECK-NEXT: unreachable ; ret i16 %p1 } diff --git a/llvm/test/Transforms/SCCP/arg-type-mismatch.ll b/llvm/test/Transforms/SCCP/arg-type-mismatch.ll --- a/llvm/test/Transforms/SCCP/arg-type-mismatch.ll +++ b/llvm/test/Transforms/SCCP/arg-type-mismatch.ll @@ -15,7 +15,7 @@ define internal i16 @bar(i16 %p1, i16 %p2) { ; CHECK-LABEL: @bar( -; CHECK-NEXT: ret i16 [[P2:%.*]] +; CHECK-NEXT: unreachable ; ret i16 %p2 }