Skip to content

Commit 90bb50b

Browse files
changpengronlieb
authored andcommitted
[FunctionAttrs] Unconditionally perform argument attribute inference in the first function-attrs pass
Fix lit test too Summary: Argument attributes like NoAlias and ReadOnly could affect memoryssa and thus earlyCSE in the function simplification pipeline. https://reviews.llvm.org/D145210 adjusted PostOrderFunctionAttrs placement and caused the argument attributes not referred for the use in the pipeline. This work (initiated by @nikic) unconditionally performs argument attribute inference in the first function-attrs pass. Reviewers: aeubanks and nikic Differential Revision: https://reviews.llvm.org/D156397 Change-Id: If9d1a1b165b708dddc03dfb4d33de2ee48e42844
1 parent e5e6fd1 commit 90bb50b

File tree

9 files changed

+66
-36
lines changed

9 files changed

+66
-36
lines changed

clang/test/CodeGenOpenCL/amdgpu-abi-struct-coerce.cl

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ void func_single_struct_element_struct_arg(single_struct_element_struct_arg_t ar
307307
// CHECK: void @func_different_size_type_pair_arg(i64 %arg1.coerce0, i32 %arg1.coerce1)
308308
void func_different_size_type_pair_arg(different_size_type_pair arg1) { }
309309

310-
// CHECK: void @func_flexible_array_arg(ptr addrspace(5) nocapture noundef byval(%struct.flexible_array) align 4 %arg)
310+
// CHECK: void @func_flexible_array_arg(ptr addrspace(5) nocapture noundef readnone byval(%struct.flexible_array) align 4 %arg)
311311
void func_flexible_array_arg(flexible_array arg) { }
312312

313313
// CHECK: define{{.*}} float @func_f32_ret()
@@ -448,12 +448,11 @@ flexible_array func_flexible_array_ret()
448448
// CHECK: define{{.*}} void @func_reg_state_lo(<4 x i32> noundef %arg0, <4 x i32> noundef %arg1, <4 x i32> noundef %arg2, i32 noundef %arg3, i32 %s.coerce0, float %s.coerce1, i32 %s.coerce2)
449449
void func_reg_state_lo(int4 arg0, int4 arg1, int4 arg2, int arg3, struct_arg_t s) { }
450450

451-
// CHECK: define{{.*}} void @func_reg_state_hi(<4 x i32> noundef %arg0, <4 x i32> noundef %arg1, <4 x i32> noundef %arg2, i32 noundef %arg3, i32 noundef %arg4, ptr addrspace(5) nocapture noundef byref(%struct.struct_arg) align 4 %0)
452-
451+
// CHECK: define{{.*}} void @func_reg_state_hi(<4 x i32> noundef %arg0, <4 x i32> noundef %arg1, <4 x i32> noundef %arg2, i32 noundef %arg3, i32 noundef %arg4, ptr addrspace(5) nocapture noundef readnone byref(%struct.struct_arg) align 4 %{{.*}})
453452
void func_reg_state_hi(int4 arg0, int4 arg1, int4 arg2, int arg3, int arg4, struct_arg_t s) { }
454453

455454
// XXX - Why don't the inner structs flatten?
456-
// CHECK: define{{.*}} void @func_reg_state_num_regs_nested_struct(<4 x i32> noundef %arg0, i32 noundef %arg1, i32 %arg2.coerce0, %struct.nested %arg2.coerce1, i32 %arg3.coerce0, %struct.nested %arg3.coerce1, ptr addrspace(5) nocapture noundef byref(%struct.num_regs_nested_struct) align 8 %0)
455+
// CHECK: define{{.*}} void @func_reg_state_num_regs_nested_struct(<4 x i32> noundef %arg0, i32 noundef %arg1, i32 %arg2.coerce0, %struct.nested %arg2.coerce1, i32 %arg3.coerce0, %struct.nested %arg3.coerce1, ptr addrspace(5) nocapture noundef readnone byref(%struct.num_regs_nested_struct) align 8 %{{.*}})
457456
void func_reg_state_num_regs_nested_struct(int4 arg0, int arg1, num_regs_nested_struct arg2, num_regs_nested_struct arg3, num_regs_nested_struct arg4) { }
458457

459458
// CHECK: define{{.*}} void @func_double_nested_struct_arg(<4 x i32> noundef %arg0, i32 noundef %arg1, i32 %arg2.coerce0, %struct.double_nested %arg2.coerce1, i16 %arg2.coerce2)
@@ -468,7 +467,7 @@ double_nested_struct func_double_nested_struct_ret(int4 arg0, int arg1) {
468467
// CHECK: define{{.*}} void @func_large_struct_padding_arg_direct(i8 %arg.coerce0, i32 %arg.coerce1, i8 %arg.coerce2, i32 %arg.coerce3, i8 %arg.coerce4, i8 %arg.coerce5, i16 %arg.coerce6, i16 %arg.coerce7, [3 x i8] %arg.coerce8, i64 %arg.coerce9, i32 %arg.coerce10, i8 %arg.coerce11, i32 %arg.coerce12, i16 %arg.coerce13, i8 %arg.coerce14)
469468
void func_large_struct_padding_arg_direct(large_struct_padding arg) { }
470469

471-
// CHECK: define{{.*}} void @func_large_struct_padding_arg_store(ptr addrspace(1) nocapture noundef writeonly %out, ptr addrspace(5) nocapture noundef readonly byref(%struct.large_struct_padding) align 8 %0)
470+
// CHECK: define{{.*}} void @func_large_struct_padding_arg_store(ptr addrspace(1) nocapture noundef writeonly %out, ptr addrspace(5) nocapture noundef readonly byref(%struct.large_struct_padding) align 8 %{{.*}})
472471
void func_large_struct_padding_arg_store(global large_struct_padding* out, large_struct_padding arg) {
473472
*out = arg;
474473
}
@@ -478,23 +477,23 @@ void v3i32_reg_count(int3 arg1, int3 arg2, int3 arg3, int3 arg4, struct_arg_t ar
478477

479478
// Function signature from blender, nothing should be passed byval. The v3i32
480479
// should not count as 4 passed registers.
481-
// CHECK: define{{.*}} void @v3i32_pair_reg_count(ptr addrspace(5) nocapture noundef %arg0, <3 x i32> %arg1.coerce0, <3 x i32> %arg1.coerce1, <3 x i32> noundef %arg2, <3 x i32> %arg3.coerce0, <3 x i32> %arg3.coerce1, <3 x i32> noundef %arg4, float noundef %arg5)
480+
// CHECK: define{{.*}} void @v3i32_pair_reg_count(ptr addrspace(5) nocapture noundef readnone %arg0, <3 x i32> %arg1.coerce0, <3 x i32> %arg1.coerce1, <3 x i32> noundef %arg2, <3 x i32> %arg3.coerce0, <3 x i32> %arg3.coerce1, <3 x i32> noundef %arg4, float noundef %arg5)
482481
void v3i32_pair_reg_count(int3_pair *arg0, int3_pair arg1, int3 arg2, int3_pair arg3, int3 arg4, float arg5) { }
483482

484483
// Each short4 should fit pack into 2 registers.
485484
// CHECK: define{{.*}} void @v4i16_reg_count(<4 x i16> noundef %arg0, <4 x i16> noundef %arg1, <4 x i16> noundef %arg2, <4 x i16> noundef %arg3, <4 x i16> noundef %arg4, <4 x i16> noundef %arg5, i32 %arg6.coerce0, i32 %arg6.coerce1, i32 %arg6.coerce2, i32 %arg6.coerce3)
486485
void v4i16_reg_count(short4 arg0, short4 arg1, short4 arg2, short4 arg3,
487486
short4 arg4, short4 arg5, struct_4regs arg6) { }
488487

489-
// CHECK: define{{.*}} void @v4i16_pair_reg_count_over(<4 x i16> noundef %arg0, <4 x i16> noundef %arg1, <4 x i16> noundef %arg2, <4 x i16> noundef %arg3, <4 x i16> noundef %arg4, <4 x i16> noundef %arg5, <4 x i16> noundef %arg6, ptr addrspace(5) nocapture noundef byref(%struct.struct_4regs) align 4 %0)
488+
// CHECK: define{{.*}} void @v4i16_pair_reg_count_over(<4 x i16> noundef %arg0, <4 x i16> noundef %arg1, <4 x i16> noundef %arg2, <4 x i16> noundef %arg3, <4 x i16> noundef %arg4, <4 x i16> noundef %arg5, <4 x i16> noundef %arg6, ptr addrspace(5) nocapture noundef readnone byref(%struct.struct_4regs) align 4 %{{.*}})
490489
void v4i16_pair_reg_count_over(short4 arg0, short4 arg1, short4 arg2, short4 arg3,
491490
short4 arg4, short4 arg5, short4 arg6, struct_4regs arg7) { }
492491

493492
// CHECK: define{{.*}} void @v3i16_reg_count(<3 x i16> noundef %arg0, <3 x i16> noundef %arg1, <3 x i16> noundef %arg2, <3 x i16> noundef %arg3, <3 x i16> noundef %arg4, <3 x i16> noundef %arg5, i32 %arg6.coerce0, i32 %arg6.coerce1, i32 %arg6.coerce2, i32 %arg6.coerce3)
494493
void v3i16_reg_count(short3 arg0, short3 arg1, short3 arg2, short3 arg3,
495494
short3 arg4, short3 arg5, struct_4regs arg6) { }
496495

497-
// CHECK: define{{.*}} void @v3i16_reg_count_over(<3 x i16> noundef %arg0, <3 x i16> noundef %arg1, <3 x i16> noundef %arg2, <3 x i16> noundef %arg3, <3 x i16> noundef %arg4, <3 x i16> noundef %arg5, <3 x i16> noundef %arg6, ptr addrspace(5) nocapture noundef byref(%struct.struct_4regs) align 4 %0)
496+
// CHECK: define{{.*}} void @v3i16_reg_count_over(<3 x i16> noundef %arg0, <3 x i16> noundef %arg1, <3 x i16> noundef %arg2, <3 x i16> noundef %arg3, <3 x i16> noundef %arg4, <3 x i16> noundef %arg5, <3 x i16> noundef %arg6, ptr addrspace(5) nocapture noundef readnone byref(%struct.struct_4regs) align 4 %{{.*}})
498497
void v3i16_reg_count_over(short3 arg0, short3 arg1, short3 arg2, short3 arg3,
499498
short3 arg4, short3 arg5, short3 arg6, struct_4regs arg7) { }
500499

@@ -504,7 +503,7 @@ void v2i16_reg_count(short2 arg0, short2 arg1, short2 arg2, short2 arg3,
504503
short2 arg8, short2 arg9, short2 arg10, short2 arg11,
505504
struct_4regs arg13) { }
506505

507-
// CHECK: define{{.*}} void @v2i16_reg_count_over(<2 x i16> noundef %arg0, <2 x i16> noundef %arg1, <2 x i16> noundef %arg2, <2 x i16> noundef %arg3, <2 x i16> noundef %arg4, <2 x i16> noundef %arg5, <2 x i16> noundef %arg6, <2 x i16> noundef %arg7, <2 x i16> noundef %arg8, <2 x i16> noundef %arg9, <2 x i16> noundef %arg10, <2 x i16> noundef %arg11, <2 x i16> noundef %arg12, ptr addrspace(5) nocapture noundef byref(%struct.struct_4regs) align 4 %0)
506+
// CHECK: define{{.*}} void @v2i16_reg_count_over(<2 x i16> noundef %arg0, <2 x i16> noundef %arg1, <2 x i16> noundef %arg2, <2 x i16> noundef %arg3, <2 x i16> noundef %arg4, <2 x i16> noundef %arg5, <2 x i16> noundef %arg6, <2 x i16> noundef %arg7, <2 x i16> noundef %arg8, <2 x i16> noundef %arg9, <2 x i16> noundef %arg10, <2 x i16> noundef %arg11, <2 x i16> noundef %arg12, ptr addrspace(5) nocapture noundef readnone byref(%struct.struct_4regs) align 4 %{{.*}})
508507
void v2i16_reg_count_over(short2 arg0, short2 arg1, short2 arg2, short2 arg3,
509508
short2 arg4, short2 arg5, short2 arg6, short2 arg7,
510509
short2 arg8, short2 arg9, short2 arg10, short2 arg11,
@@ -514,7 +513,7 @@ void v2i16_reg_count_over(short2 arg0, short2 arg1, short2 arg2, short2 arg3,
514513
void v2i8_reg_count(char2 arg0, char2 arg1, char2 arg2, char2 arg3,
515514
char2 arg4, char2 arg5, struct_4regs arg6) { }
516515

517-
// CHECK: define{{.*}} void @v2i8_reg_count_over(<2 x i8> noundef %arg0, <2 x i8> noundef %arg1, <2 x i8> noundef %arg2, <2 x i8> noundef %arg3, <2 x i8> noundef %arg4, <2 x i8> noundef %arg5, i32 noundef %arg6, ptr addrspace(5) nocapture noundef byref(%struct.struct_4regs) align 4 %0)
516+
// CHECK: define{{.*}} void @v2i8_reg_count_over(<2 x i8> noundef %arg0, <2 x i8> noundef %arg1, <2 x i8> noundef %arg2, <2 x i8> noundef %arg3, <2 x i8> noundef %arg4, <2 x i8> noundef %arg5, i32 noundef %arg6, ptr addrspace(5) nocapture noundef readnone byref(%struct.struct_4regs) align 4 %{{.*}})
518517
void v2i8_reg_count_over(char2 arg0, char2 arg1, char2 arg2, char2 arg3,
519518
char2 arg4, char2 arg5, int arg6, struct_4regs arg7) { }
520519

clang/test/CodeGenOpenCL/kernel-param-alignment.cl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ kernel void test(
1717
global void *v,
1818
global struct packed *p) {
1919
// CHECK-LABEL: spir_kernel void @test(
20-
// CHECK-SAME: ptr nocapture noundef align 4 %i32,
21-
// CHECK-SAME: ptr nocapture noundef align 8 %i64,
22-
// CHECK-SAME: ptr nocapture noundef align 16 %v4i32,
23-
// CHECK-SAME: ptr nocapture noundef align 8 %v2f32,
24-
// CHECK-SAME: ptr nocapture noundef %v,
25-
// CHECK-SAME: ptr nocapture noundef align 1 %p)
20+
// CHECK-SAME: ptr nocapture noundef readnone align 4 %i32,
21+
// CHECK-SAME: ptr nocapture noundef readnone align 8 %i64,
22+
// CHECK-SAME: ptr nocapture noundef readnone align 16 %v4i32,
23+
// CHECK-SAME: ptr nocapture noundef readnone align 8 %v2f32,
24+
// CHECK-SAME: ptr nocapture noundef readnone %v,
25+
// CHECK-SAME: ptr nocapture noundef readnone align 1 %p)
2626
}

llvm/lib/Passes/PassBuilder.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -806,7 +806,7 @@ Expected<bool> parseCoroSplitPassOptions(StringRef Params) {
806806
}
807807

808808
Expected<bool> parsePostOrderFunctionAttrsPassOptions(StringRef Params) {
809-
return parseSinglePassOption(Params, "skip-non-recursive",
809+
return parseSinglePassOption(Params, "skip-non-recursive-function-attrs",
810810
"PostOrderFunctionAttrs");
811811
}
812812

llvm/lib/Passes/PassRegistry.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ CGSCC_PASS_WITH_PARAMS("function-attrs",
245245
return PostOrderFunctionAttrsPass(SkipNonRecursive);
246246
},
247247
parsePostOrderFunctionAttrsPassOptions,
248-
"skip-non-recursive")
248+
"skip-non-recursive-function-attrs")
249249
#undef CGSCC_PASS_WITH_PARAMS
250250

251251
#ifndef FUNCTION_ANALYSIS

llvm/lib/Transforms/IPO/FunctionAttrs.cpp

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1749,14 +1749,19 @@ static SCCNodesResult createSCCNodeSet(ArrayRef<Function *> Functions) {
17491749

17501750
template <typename AARGetterT>
17511751
static SmallSet<Function *, 8>
1752-
deriveAttrsInPostOrder(ArrayRef<Function *> Functions, AARGetterT &&AARGetter) {
1752+
deriveAttrsInPostOrder(ArrayRef<Function *> Functions, AARGetterT &&AARGetter,
1753+
bool ArgAttrsOnly) {
17531754
SCCNodesResult Nodes = createSCCNodeSet(Functions);
17541755

17551756
// Bail if the SCC only contains optnone functions.
17561757
if (Nodes.SCCNodes.empty())
17571758
return {};
17581759

17591760
SmallSet<Function *, 8> Changed;
1761+
if (ArgAttrsOnly) {
1762+
addArgumentAttrs(Nodes.SCCNodes, Changed);
1763+
return Changed;
1764+
}
17601765

17611766
addArgumentReturnedAttrs(Nodes.SCCNodes, Changed);
17621767
addMemoryAttrs(Nodes.SCCNodes, AARGetter, Changed);
@@ -1791,10 +1796,13 @@ PreservedAnalyses PostOrderFunctionAttrsPass::run(LazyCallGraph::SCC &C,
17911796
LazyCallGraph &CG,
17921797
CGSCCUpdateResult &) {
17931798
// Skip non-recursive functions if requested.
1799+
// Only infer argument attributes for non-recursive functions, because
1800+
// it can affect optimization behavior in conjunction with noalias.
1801+
bool ArgAttrsOnly = false;
17941802
if (C.size() == 1 && SkipNonRecursive) {
17951803
LazyCallGraph::Node &N = *C.begin();
17961804
if (!N->lookup(N))
1797-
return PreservedAnalyses::all();
1805+
ArgAttrsOnly = true;
17981806
}
17991807

18001808
FunctionAnalysisManager &FAM =
@@ -1811,7 +1819,8 @@ PreservedAnalyses PostOrderFunctionAttrsPass::run(LazyCallGraph::SCC &C,
18111819
Functions.push_back(&N.getFunction());
18121820
}
18131821

1814-
auto ChangedFunctions = deriveAttrsInPostOrder(Functions, AARGetter);
1822+
auto ChangedFunctions =
1823+
deriveAttrsInPostOrder(Functions, AARGetter, ArgAttrsOnly);
18151824
if (ChangedFunctions.empty())
18161825
return PreservedAnalyses::all();
18171826

@@ -1847,7 +1856,7 @@ void PostOrderFunctionAttrsPass::printPipeline(
18471856
static_cast<PassInfoMixin<PostOrderFunctionAttrsPass> *>(this)->printPipeline(
18481857
OS, MapClassName2PassName);
18491858
if (SkipNonRecursive)
1850-
OS << "<skip-non-recursive>";
1859+
OS << "<skip-non-recursive-function-attrs>";
18511860
}
18521861

18531862
template <typename AARGetterT>

llvm/test/Other/new-pm-print-pipeline.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@
9999
; CHECK-28: function(instcombine<max-iterations=1;no-use-loop-info;verify-fixpoint>,instcombine<max-iterations=42;use-loop-info;no-verify-fixpoint>)
100100

101101
;; Test function-attrs
102-
; RUN: opt -disable-output -disable-verify -print-pipeline-passes -passes='cgscc(function-attrs<skip-non-recursive>)' < %s | FileCheck %s --match-full-lines --check-prefixes=CHECK-29
103-
; CHECK-29: cgscc(function-attrs<skip-non-recursive>)
102+
; RUN: opt -disable-output -disable-verify -print-pipeline-passes -passes='cgscc(function-attrs<skip-non-recursive-function-attrs>)' < %s | FileCheck %s --match-full-lines --check-prefixes=CHECK-29
103+
; CHECK-29: cgscc(function-attrs<skip-non-recursive-function-attrs>)
104104

105105
;; Test cgscc -> function adaptor
106106
; RUN: opt -disable-output -disable-verify -print-pipeline-passes -passes='cgscc(function<eager-inv;no-rerun>(no-op-function))' < %s | FileCheck %s --match-full-lines --check-prefixes=CHECK-30

llvm/test/Transforms/InstCombine/unused-nonnull.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ target triple = "x86_64-unknown-linux-gnu"
99

1010
define i32 @main(i32 %argc, ptr %argv) #0 {
1111
; CHECK-LABEL: define {{[^@]+}}@main
12-
; CHECK-SAME: (i32 [[ARGC:%.*]], ptr nocapture readnone [[ARGV:%.*]]) local_unnamed_addr #[[ATTR0:[0-9]+]] {
12+
; CHECK-SAME: (i32 [[ARGC:%.*]], ptr nocapture readonly [[ARGV:%.*]]) local_unnamed_addr #[[ATTR0:[0-9]+]] {
1313
; CHECK-NEXT: entry:
1414
; CHECK-NEXT: [[TMP0:%.*]] = icmp slt i32 [[ARGC]], 2
1515
; CHECK-NEXT: [[SPEC_SELECT:%.*]] = select i1 [[TMP0]], i32 0, i32 [[ARGC]]
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 2
2+
; RUN: opt -S -O3 -memssa-check-limit=1 -memdep-block-scan-limit=1 < %s | FileCheck %s
3+
4+
define i32 @f(ptr noalias %p, i32 %c) {
5+
; CHECK-LABEL: define i32 @f
6+
; CHECK-SAME: (ptr noalias nocapture readonly [[P:%.*]], i32 [[C:%.*]]) local_unnamed_addr {
7+
; CHECK-NEXT: tail call void @g()
8+
; CHECK-NEXT: tail call void @g()
9+
; CHECK-NEXT: tail call void @g()
10+
; CHECK-NEXT: tail call void @g()
11+
; CHECK-NEXT: tail call void @g()
12+
; CHECK-NEXT: tail call void @g()
13+
; CHECK-NEXT: ret i32 0
14+
;
15+
%i = load i32, ptr %p
16+
call void @g()
17+
call void @g()
18+
call void @g()
19+
call void @g()
20+
call void @g()
21+
call void @g()
22+
%i2 = load i32, ptr %p
23+
%r = sub i32 %i, %i2
24+
ret i32 %r
25+
}
26+
27+
declare void @g()

revert_patches.txt

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,18 @@ SROA breaks MIOpen
22
Revert "[SROA] Create additional vector type candidates based on store and load slices"
33
Revert "[SROA] Fix bug where CandidateTys is appended while being iterated"
44

5-
breaks rccl build:
6-
Revert "Implement P2361 Unevaluated string literals"
7-
8-
Revert "[Clang] Implement P2741R3 - user-generated static_assert messages "
9-
Revert "[Clang] Fix crash in CIndex, when visiting a static_assert without message"
5+
Rana: HipCatch2 and olcTest conformance fails
106
Revert "[AMDGPU] __builtin_amdgcn_read_exec_* should be implemented with llvm.amdgcn.ballot"
11-
Revert "[Clang] Handle static_assert messages with an expression started by a literal"
7+
8+
missing executable in build:
129
Revert "[RemarkUtil] Refactor llvm-remarkutil to include size-diff "
13-
Revert "Enable concatenation of predefined identifiers "
14-
Revert "[FunctionAttrs] Unconditionally perform argument attribute inference in the first function-attrs pass"
15-
Revert "[clang][test] Fix LIT test failures for the following commit"
16-
Revert "[Clang] Produce a warning instead of an error in unevaluated strings before C++26 "
1710

11+
Johannes: breakage
1812
Revert "[OpenMP] Disable early vectorization of loads/stores in the runtime "
1913
asserts in snap and MI-Teams
2014

15+
Nicole and Saiyed:
2116
Revert " [OpenMP][DeviceRTL][AMDGPU] Support code object version 5"
2217

2318
Revert "[Parser] Parse string literal arguments of 'avail"
24-
needs Dave's restores to land
19+

0 commit comments

Comments
 (0)