[Inline] Don't add noalias metadata to inaccessiblememonly calls

It will not do anything useful for them, as we already know that
they don't modref with any accessible memory.

In particular, this prevents noalias metadata from being placed
on noalias.scope.decl intrinsics. This reduces the amount of
metadata needed, and makes it more likely that unnecessary decls
can be eliminated.
This commit is contained in:
Nikita Popov 2021-04-17 14:51:29 +02:00
parent 595394321d
commit e68b12c99e
3 changed files with 72 additions and 72 deletions

View File

@ -1041,6 +1041,11 @@ static void AddAliasScopeMetadata(CallBase &CB, ValueToValueMapTy &VMap,
IsFuncCall = true;
if (CalleeAAR) {
FunctionModRefBehavior MRB = CalleeAAR->getModRefBehavior(Call);
// We'll retain this knowledge without additional metadata.
if (AAResults::onlyAccessesInaccessibleMem(MRB))
continue;
if (AAResults::onlyAccessesArgPointees(MRB))
IsArgMemOnlyCall = true;
}

View File

@ -29,10 +29,10 @@ define void @caller_equals_callee(i32* noalias %p0, i32* noalias %p1, i32 %cnt)
; CHECK-NEXT: call void @llvm.experimental.noalias.scope.decl(metadata !8)
; CHECK-NEXT: [[ADD_PTR_I:%.*]] = getelementptr inbounds i32, i32* [[ADD_PTR2]], i64 2
; CHECK-NEXT: [[ADD_PTR1_I:%.*]] = getelementptr inbounds i32, i32* [[ADD_PTR3]], i64 2
; CHECK-NEXT: tail call void @llvm.experimental.noalias.scope.decl(metadata !10), !noalias !13
; CHECK-NEXT: tail call void @llvm.experimental.noalias.scope.decl(metadata !14), !noalias !13
; CHECK-NEXT: store i32 10, i32* [[ADD_PTR_I]], align 4, !alias.scope !16, !noalias !17
; CHECK-NEXT: store i32 20, i32* [[ADD_PTR1_I]], align 4, !alias.scope !17, !noalias !16
; CHECK-NEXT: tail call void @llvm.experimental.noalias.scope.decl(metadata !10)
; CHECK-NEXT: tail call void @llvm.experimental.noalias.scope.decl(metadata !13)
; CHECK-NEXT: store i32 10, i32* [[ADD_PTR_I]], align 4, !alias.scope !15, !noalias !16
; CHECK-NEXT: store i32 20, i32* [[ADD_PTR1_I]], align 4, !alias.scope !16, !noalias !15
; CHECK-NEXT: store i32 11, i32* [[ADD_PTR2]], align 4, !alias.scope !5, !noalias !8
; CHECK-NEXT: store i32 12, i32* [[P1]], align 4
; CHECK-NEXT: br label [[IF_END]]
@ -71,32 +71,32 @@ define void @test01(i32* noalias %p0, i32* noalias %p1, i32 %cnt) {
; CHECK-NEXT: store i32 13, i32* [[P0]], align 4
; CHECK-NEXT: [[ADD_PTR:%.*]] = getelementptr inbounds i32, i32* [[P0]], i64 1
; CHECK-NEXT: [[ADD_PTR1:%.*]] = getelementptr inbounds i32, i32* [[P1]], i64 1
; CHECK-NEXT: call void @llvm.experimental.noalias.scope.decl(metadata !18)
; CHECK-NEXT: call void @llvm.experimental.noalias.scope.decl(metadata !21)
; CHECK-NEXT: call void @llvm.experimental.noalias.scope.decl(metadata !17)
; CHECK-NEXT: call void @llvm.experimental.noalias.scope.decl(metadata !20)
; CHECK-NEXT: [[ADD_PTR_I:%.*]] = getelementptr inbounds i32, i32* [[ADD_PTR]], i64 2
; CHECK-NEXT: [[ADD_PTR1_I:%.*]] = getelementptr inbounds i32, i32* [[ADD_PTR1]], i64 2
; CHECK-NEXT: call void @llvm.experimental.noalias.scope.decl(metadata !23), !noalias !26
; CHECK-NEXT: call void @llvm.experimental.noalias.scope.decl(metadata !27), !noalias !26
; CHECK-NEXT: store i32 10, i32* [[ADD_PTR_I]], align 4, !alias.scope !29, !noalias !30
; CHECK-NEXT: store i32 20, i32* [[ADD_PTR1_I]], align 4, !alias.scope !30, !noalias !29
; CHECK-NEXT: call void @llvm.experimental.noalias.scope.decl(metadata !22)
; CHECK-NEXT: call void @llvm.experimental.noalias.scope.decl(metadata !25)
; CHECK-NEXT: store i32 10, i32* [[ADD_PTR_I]], align 4, !alias.scope !27, !noalias !28
; CHECK-NEXT: store i32 20, i32* [[ADD_PTR1_I]], align 4, !alias.scope !28, !noalias !27
; CHECK-NEXT: [[CMP_I:%.*]] = icmp eq i32 [[CNT]], 0
; CHECK-NEXT: br i1 [[CMP_I]], label [[IF_THEN_I:%.*]], label [[IF_ELSE_I:%.*]]
; CHECK: if.then.i:
; CHECK-NEXT: store i32 11, i32* [[ADD_PTR]], align 4, !alias.scope !18, !noalias !21
; CHECK-NEXT: store i32 11, i32* [[ADD_PTR]], align 4, !alias.scope !17, !noalias !20
; CHECK-NEXT: br label [[CALLER_EQUALS_CALLEE_EXIT:%.*]]
; CHECK: if.else.i:
; CHECK-NEXT: [[ADD_PTR2_I:%.*]] = getelementptr inbounds i32, i32* [[ADD_PTR1]], i64 1
; CHECK-NEXT: [[ADD_PTR3_I:%.*]] = getelementptr inbounds i32, i32* [[ADD_PTR]], i64 1
; CHECK-NEXT: call void @llvm.experimental.noalias.scope.decl(metadata !31), !noalias !26
; CHECK-NEXT: call void @llvm.experimental.noalias.scope.decl(metadata !34), !noalias !26
; CHECK-NEXT: call void @llvm.experimental.noalias.scope.decl(metadata !29)
; CHECK-NEXT: call void @llvm.experimental.noalias.scope.decl(metadata !32)
; CHECK-NEXT: [[ADD_PTR_I_I:%.*]] = getelementptr inbounds i32, i32* [[ADD_PTR2_I]], i64 2
; CHECK-NEXT: [[ADD_PTR1_I_I:%.*]] = getelementptr inbounds i32, i32* [[ADD_PTR3_I]], i64 2
; CHECK-NEXT: call void @llvm.experimental.noalias.scope.decl(metadata !36), !noalias !39
; CHECK-NEXT: call void @llvm.experimental.noalias.scope.decl(metadata !40), !noalias !39
; CHECK-NEXT: store i32 10, i32* [[ADD_PTR_I_I]], align 4, !alias.scope !42, !noalias !43
; CHECK-NEXT: store i32 20, i32* [[ADD_PTR1_I_I]], align 4, !alias.scope !43, !noalias !42
; CHECK-NEXT: store i32 11, i32* [[ADD_PTR2_I]], align 4, !alias.scope !44, !noalias !45
; CHECK-NEXT: store i32 12, i32* [[ADD_PTR1]], align 4, !alias.scope !21, !noalias !18
; CHECK-NEXT: call void @llvm.experimental.noalias.scope.decl(metadata !34)
; CHECK-NEXT: call void @llvm.experimental.noalias.scope.decl(metadata !37)
; CHECK-NEXT: store i32 10, i32* [[ADD_PTR_I_I]], align 4, !alias.scope !39, !noalias !40
; CHECK-NEXT: store i32 20, i32* [[ADD_PTR1_I_I]], align 4, !alias.scope !40, !noalias !39
; CHECK-NEXT: store i32 11, i32* [[ADD_PTR2_I]], align 4, !alias.scope !41, !noalias !42
; CHECK-NEXT: store i32 12, i32* [[ADD_PTR1]], align 4, !alias.scope !20, !noalias !17
; CHECK-NEXT: br label [[CALLER_EQUALS_CALLEE_EXIT]]
; CHECK: caller_equals_callee.exit:
; CHECK-NEXT: ret void
@ -130,37 +130,33 @@ attributes #0 = { inaccessiblememonly nofree nosync nounwind willreturn }
; CHECK: !10 = !{!11}
; CHECK: !11 = distinct !{!11, !12, !"do_store: %p0"}
; CHECK: !12 = distinct !{!12, !"do_store"}
; CHECK: !13 = !{!6, !9}
; CHECK: !14 = !{!15}
; CHECK: !15 = distinct !{!15, !12, !"do_store: %p1"}
; CHECK: !16 = !{!11, !6}
; CHECK: !17 = !{!15, !9}
; CHECK: !18 = !{!19}
; CHECK: !19 = distinct !{!19, !20, !"caller_equals_callee: %p0"}
; CHECK: !20 = distinct !{!20, !"caller_equals_callee"}
; CHECK: !21 = !{!22}
; CHECK: !22 = distinct !{!22, !20, !"caller_equals_callee: %p1"}
; CHECK: !23 = !{!24}
; CHECK: !24 = distinct !{!24, !25, !"do_store: %p0"}
; CHECK: !25 = distinct !{!25, !"do_store"}
; CHECK: !26 = !{!19, !22}
; CHECK: !27 = !{!28}
; CHECK: !28 = distinct !{!28, !25, !"do_store: %p1"}
; CHECK: !29 = !{!24, !19}
; CHECK: !30 = !{!28, !22}
; CHECK: !31 = !{!32}
; CHECK: !32 = distinct !{!32, !33, !"caller_equals_callee: %p0"}
; CHECK: !33 = distinct !{!33, !"caller_equals_callee"}
; CHECK: !13 = !{!14}
; CHECK: !14 = distinct !{!14, !12, !"do_store: %p1"}
; CHECK: !15 = !{!11, !6}
; CHECK: !16 = !{!14, !9}
; CHECK: !17 = !{!18}
; CHECK: !18 = distinct !{!18, !19, !"caller_equals_callee: %p0"}
; CHECK: !19 = distinct !{!19, !"caller_equals_callee"}
; CHECK: !20 = !{!21}
; CHECK: !21 = distinct !{!21, !19, !"caller_equals_callee: %p1"}
; CHECK: !22 = !{!23}
; CHECK: !23 = distinct !{!23, !24, !"do_store: %p0"}
; CHECK: !24 = distinct !{!24, !"do_store"}
; CHECK: !25 = !{!26}
; CHECK: !26 = distinct !{!26, !24, !"do_store: %p1"}
; CHECK: !27 = !{!23, !18}
; CHECK: !28 = !{!26, !21}
; CHECK: !29 = !{!30}
; CHECK: !30 = distinct !{!30, !31, !"caller_equals_callee: %p0"}
; CHECK: !31 = distinct !{!31, !"caller_equals_callee"}
; CHECK: !32 = !{!33}
; CHECK: !33 = distinct !{!33, !31, !"caller_equals_callee: %p1"}
; CHECK: !34 = !{!35}
; CHECK: !35 = distinct !{!35, !33, !"caller_equals_callee: %p1"}
; CHECK: !36 = !{!37}
; CHECK: !37 = distinct !{!37, !38, !"do_store: %p0"}
; CHECK: !38 = distinct !{!38, !"do_store"}
; CHECK: !39 = !{!32, !35, !19, !22}
; CHECK: !40 = !{!41}
; CHECK: !41 = distinct !{!41, !38, !"do_store: %p1"}
; CHECK: !42 = !{!37, !32, !22}
; CHECK: !43 = !{!41, !35, !19}
; CHECK: !44 = !{!32, !22}
; CHECK: !45 = !{!35, !19}
; CHECK: !35 = distinct !{!35, !36, !"do_store: %p0"}
; CHECK: !36 = distinct !{!36, !"do_store"}
; CHECK: !37 = !{!38}
; CHECK: !38 = distinct !{!38, !36, !"do_store: %p1"}
; CHECK: !39 = !{!35, !30, !21}
; CHECK: !40 = !{!38, !33, !18}
; CHECK: !41 = !{!30, !21}
; CHECK: !42 = !{!33, !18}

View File

@ -71,21 +71,21 @@ define void @foo2(float* nocapture %a, float* nocapture %b, float* nocapture rea
; CHECK-NEXT: entry:
; CHECK-NEXT: call void @llvm.experimental.noalias.scope.decl(metadata !5)
; CHECK-NEXT: call void @llvm.experimental.noalias.scope.decl(metadata !8)
; CHECK-NEXT: call void @llvm.experimental.noalias.scope.decl(metadata !10) [[ATTR2:#.*]], !noalias !13
; CHECK-NEXT: call void @llvm.experimental.noalias.scope.decl(metadata !14) [[ATTR2]], !noalias !13
; CHECK-NEXT: [[TMP0:%.*]] = load float, float* [[C]], align 4, !alias.scope !16, !noalias !17
; CHECK-NEXT: call void @llvm.experimental.noalias.scope.decl(metadata !10) [[ATTR2:#.*]]
; CHECK-NEXT: call void @llvm.experimental.noalias.scope.decl(metadata !13) [[ATTR2]]
; CHECK-NEXT: [[TMP0:%.*]] = load float, float* [[C]], align 4, !alias.scope !15, !noalias !16
; CHECK-NEXT: [[ARRAYIDX_I_I:%.*]] = getelementptr inbounds float, float* [[A]], i64 5
; CHECK-NEXT: store float [[TMP0]], float* [[ARRAYIDX_I_I]], align 4, !alias.scope !17, !noalias !16
; CHECK-NEXT: store float [[TMP0]], float* [[ARRAYIDX_I_I]], align 4, !alias.scope !16, !noalias !15
; CHECK-NEXT: [[TMP1:%.*]] = load float, float* [[C]], align 4, !alias.scope !8, !noalias !5
; CHECK-NEXT: [[ARRAYIDX_I:%.*]] = getelementptr inbounds float, float* [[A]], i64 7
; CHECK-NEXT: store float [[TMP1]], float* [[ARRAYIDX_I]], align 4, !alias.scope !5, !noalias !8
; CHECK-NEXT: call void @llvm.experimental.noalias.scope.decl(metadata !18)
; CHECK-NEXT: call void @llvm.experimental.noalias.scope.decl(metadata !21)
; CHECK-NEXT: [[TMP2:%.*]] = load float, float* [[C]], align 4, !noalias !23
; CHECK-NEXT: call void @llvm.experimental.noalias.scope.decl(metadata !17)
; CHECK-NEXT: call void @llvm.experimental.noalias.scope.decl(metadata !20)
; CHECK-NEXT: [[TMP2:%.*]] = load float, float* [[C]], align 4, !noalias !22
; CHECK-NEXT: [[ARRAYIDX_I1:%.*]] = getelementptr inbounds float, float* [[A]], i64 6
; CHECK-NEXT: store float [[TMP2]], float* [[ARRAYIDX_I1]], align 4, !alias.scope !18, !noalias !21
; CHECK-NEXT: store float [[TMP2]], float* [[ARRAYIDX_I1]], align 4, !alias.scope !17, !noalias !20
; CHECK-NEXT: [[ARRAYIDX1_I:%.*]] = getelementptr inbounds float, float* [[B]], i64 8
; CHECK-NEXT: store float [[TMP2]], float* [[ARRAYIDX1_I]], align 4, !alias.scope !21, !noalias !18
; CHECK-NEXT: store float [[TMP2]], float* [[ARRAYIDX1_I]], align 4, !alias.scope !20, !noalias !17
; CHECK-NEXT: [[TMP3:%.*]] = load float, float* [[C]], align 4
; CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds float, float* [[A]], i64 7
; CHECK-NEXT: store float [[TMP3]], float* [[ARRAYIDX]], align 4
@ -113,17 +113,16 @@ entry:
; CHECK: !10 = !{!11}
; CHECK: !11 = distinct !{!11, !12, !"hello: %a"}
; CHECK: !12 = distinct !{!12, !"hello"}
; CHECK: !13 = !{!6, !9}
; CHECK: !14 = !{!15}
; CHECK: !15 = distinct !{!15, !12, !"hello: %c"}
; CHECK: !16 = !{!15, !9}
; CHECK: !17 = !{!11, !6}
; CHECK: !18 = !{!19}
; CHECK: !19 = distinct !{!19, !20, !"hello2: %a"}
; CHECK: !20 = distinct !{!20, !"hello2"}
; CHECK: !21 = !{!22}
; CHECK: !22 = distinct !{!22, !20, !"hello2: %b"}
; CHECK: !23 = !{!19, !22}
; CHECK: !13 = !{!14}
; CHECK: !14 = distinct !{!14, !12, !"hello: %c"}
; CHECK: !15 = !{!14, !9}
; CHECK: !16 = !{!11, !6}
; CHECK: !17 = !{!18}
; CHECK: !18 = distinct !{!18, !19, !"hello2: %a"}
; CHECK: !19 = distinct !{!19, !"hello2"}
; CHECK: !20 = !{!21}
; CHECK: !21 = distinct !{!21, !19, !"hello2: %b"}
; CHECK: !22 = !{!18, !21}
attributes #0 = { nounwind uwtable }