[llvm] f4a3969 - [Inline] Fix incorrectly dropped noalias metadata

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 18 12:23:05 PST 2020


Author: Nikita Popov
Date: 2020-11-18T21:22:50+01:00
New Revision: f4a3969bffceac2df4bee10992ea48136122cae0

URL: https://github.com/llvm/llvm-project/commit/f4a3969bffceac2df4bee10992ea48136122cae0
DIFF: https://github.com/llvm/llvm-project/commit/f4a3969bffceac2df4bee10992ea48136122cae0.diff

LOG: [Inline] Fix incorrectly dropped noalias metadata

This is the same fix as 23aeadb89df38406dc4d929d08286f7ce31040eb,
just for CloneScopedAliasMetadata rather than PropagateCallSiteMetadata.

In this case the previous outcome was incorrectly dropped metadata,
as it was not part of the computed metadata map.

The real change in the test is that the first load now retains
metadata, the rest of the changes are due to changes in metadata
numbering.

Added: 
    

Modified: 
    llvm/lib/Transforms/Utils/InlineFunction.cpp
    llvm/test/Transforms/Inline/noalias-cs.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Utils/InlineFunction.cpp b/llvm/lib/Transforms/Utils/InlineFunction.cpp
index c16433cc5289..b148f45eea17 100644
--- a/llvm/lib/Transforms/Utils/InlineFunction.cpp
+++ b/llvm/lib/Transforms/Utils/InlineFunction.cpp
@@ -892,7 +892,9 @@ static void CloneAliasScopeMetadata(CallBase &CB, ValueToValueMapTy &VMap) {
   // repacements from the map.
   for (ValueToValueMapTy::iterator VMI = VMap.begin(), VMIE = VMap.end();
        VMI != VMIE; ++VMI) {
-    if (!VMI->second)
+    // Check that key is an instruction, to skip the Argument mapping, which
+    // points to an instruction in the original function, not the inlined one.
+    if (!VMI->second || !isa<Instruction>(VMI->first))
       continue;
 
     Instruction *NI = dyn_cast<Instruction>(VMI->second);

diff  --git a/llvm/test/Transforms/Inline/noalias-cs.ll b/llvm/test/Transforms/Inline/noalias-cs.ll
index 6e727a1001f9..a8cbf80d5ff2 100644
--- a/llvm/test/Transforms/Inline/noalias-cs.ll
+++ b/llvm/test/Transforms/Inline/noalias-cs.ll
@@ -34,39 +34,39 @@ entry:
 define void @caller(float* nocapture %a, float* nocapture %b, float** nocapture readonly %c_ptr) #0 {
 ; CHECK-LABEL: @caller(
 ; CHECK-NEXT:  entry:
-; CHECK-NEXT:    [[C:%.*]] = load float*, float** [[C_PTR:%.*]], align 8
-; CHECK-NEXT:    [[TMP0:%.*]] = load float, float* [[C]], align 4, !noalias !6
+; CHECK-NEXT:    [[C:%.*]] = load float*, float** [[C_PTR:%.*]], align 8, !alias.scope !6
+; CHECK-NEXT:    [[TMP0:%.*]] = load float, float* [[C]], align 4, !noalias !9
 ; 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 !12, !noalias !13
+; CHECK-NEXT:    store float [[TMP0]], float* [[ARRAYIDX_I_I]], align 4, !alias.scope !13, !noalias !14
 ; CHECK-NEXT:    [[ARRAYIDX1_I_I:%.*]] = getelementptr inbounds float, float* [[B:%.*]], i64 8
-; CHECK-NEXT:    store float [[TMP0]], float* [[ARRAYIDX1_I_I]], align 4, !alias.scope !14, !noalias !15
-; CHECK-NEXT:    [[TMP1:%.*]] = load float, float* [[C]], align 4, !noalias !16
+; CHECK-NEXT:    store float [[TMP0]], float* [[ARRAYIDX1_I_I]], align 4, !alias.scope !15, !noalias !16
+; CHECK-NEXT:    [[TMP1:%.*]] = load float, float* [[C]], align 4, !noalias !6
 ; CHECK-NEXT:    [[ARRAYIDX_I:%.*]] = getelementptr inbounds float, float* [[A]], i64 7
-; CHECK-NEXT:    store float [[TMP1]], float* [[ARRAYIDX_I]], align 4, !noalias !16
-; CHECK-NEXT:    [[TMP2:%.*]] = load float, float* [[A]], align 4, !alias.scope !16, !noalias !17
+; CHECK-NEXT:    store float [[TMP1]], float* [[ARRAYIDX_I]], align 4, !noalias !6
+; CHECK-NEXT:    [[TMP2:%.*]] = load float, float* [[A]], align 4, !alias.scope !6, !noalias !17
 ; CHECK-NEXT:    [[ARRAYIDX_I_I7:%.*]] = getelementptr inbounds float, float* [[B]], i64 5
 ; CHECK-NEXT:    store float [[TMP2]], float* [[ARRAYIDX_I_I7]], align 4, !alias.scope !21, !noalias !22
 ; CHECK-NEXT:    [[ARRAYIDX1_I_I8:%.*]] = getelementptr inbounds float, float* [[B]], i64 8
 ; CHECK-NEXT:    store float [[TMP2]], float* [[ARRAYIDX1_I_I8]], align 4, !alias.scope !23, !noalias !24
-; CHECK-NEXT:    [[TMP3:%.*]] = load float, float* [[A]], align 4, !alias.scope !16
+; CHECK-NEXT:    [[TMP3:%.*]] = load float, float* [[A]], align 4, !alias.scope !6
 ; CHECK-NEXT:    [[ARRAYIDX_I9:%.*]] = getelementptr inbounds float, float* [[B]], i64 7
-; CHECK-NEXT:    store float [[TMP3]], float* [[ARRAYIDX_I9]], align 4, !alias.scope !16
-; CHECK-NEXT:    [[TMP4:%.*]] = load float, float* [[C]], align 4, !noalias !16
+; CHECK-NEXT:    store float [[TMP3]], float* [[ARRAYIDX_I9]], align 4, !alias.scope !6
+; CHECK-NEXT:    [[TMP4:%.*]] = load float, float* [[C]], align 4, !noalias !6
 ; CHECK-NEXT:    [[ARRAYIDX_I_I4:%.*]] = getelementptr inbounds float, float* [[A]], i64 5
-; CHECK-NEXT:    store float [[TMP4]], float* [[ARRAYIDX_I_I4]], align 4, !noalias !16
+; CHECK-NEXT:    store float [[TMP4]], float* [[ARRAYIDX_I_I4]], align 4, !noalias !6
 ; CHECK-NEXT:    [[ARRAYIDX1_I_I5:%.*]] = getelementptr inbounds float, float* [[B]], i64 8
-; CHECK-NEXT:    store float [[TMP4]], float* [[ARRAYIDX1_I_I5]], align 4, !noalias !16
-; CHECK-NEXT:    [[TMP5:%.*]] = load float, float* [[C]], align 4, !noalias !16
+; CHECK-NEXT:    store float [[TMP4]], float* [[ARRAYIDX1_I_I5]], align 4, !noalias !6
+; CHECK-NEXT:    [[TMP5:%.*]] = load float, float* [[C]], align 4, !noalias !6
 ; CHECK-NEXT:    [[ARRAYIDX_I6:%.*]] = getelementptr inbounds float, float* [[A]], i64 7
-; CHECK-NEXT:    store float [[TMP5]], float* [[ARRAYIDX_I6]], align 4, !noalias !16
-; CHECK-NEXT:    [[TMP6:%.*]] = load float, float* [[A]], align 4, !alias.scope !16
+; CHECK-NEXT:    store float [[TMP5]], float* [[ARRAYIDX_I6]], align 4, !noalias !6
+; CHECK-NEXT:    [[TMP6:%.*]] = load float, float* [[A]], align 4, !alias.scope !6
 ; CHECK-NEXT:    [[ARRAYIDX_I_I1:%.*]] = getelementptr inbounds float, float* [[B]], i64 5
-; CHECK-NEXT:    store float [[TMP6]], float* [[ARRAYIDX_I_I1]], align 4, !alias.scope !16
+; CHECK-NEXT:    store float [[TMP6]], float* [[ARRAYIDX_I_I1]], align 4, !alias.scope !6
 ; CHECK-NEXT:    [[ARRAYIDX1_I_I2:%.*]] = getelementptr inbounds float, float* [[B]], i64 8
-; CHECK-NEXT:    store float [[TMP6]], float* [[ARRAYIDX1_I_I2]], align 4, !alias.scope !16
-; CHECK-NEXT:    [[TMP7:%.*]] = load float, float* [[A]], align 4, !alias.scope !16
+; CHECK-NEXT:    store float [[TMP6]], float* [[ARRAYIDX1_I_I2]], align 4, !alias.scope !6
+; CHECK-NEXT:    [[TMP7:%.*]] = load float, float* [[A]], align 4, !alias.scope !6
 ; CHECK-NEXT:    [[ARRAYIDX_I3:%.*]] = getelementptr inbounds float, float* [[B]], i64 7
-; CHECK-NEXT:    store float [[TMP7]], float* [[ARRAYIDX_I3]], align 4, !alias.scope !16
+; CHECK-NEXT:    store float [[TMP7]], float* [[ARRAYIDX_I3]], align 4, !alias.scope !6
 ; CHECK-NEXT:    ret void
 ;
 entry:
@@ -96,23 +96,22 @@ attributes #0 = { nounwind uwtable }
 ; CHECK: !3 = distinct !{!3, !2, !"hello2: %b"}
 ; CHECK: !4 = !{!1}
 ; CHECK: !5 = !{!3}
-; CHECK: !6 = !{!7, !9, !10}
-; CHECK: !7 = distinct !{!7, !8, !"hello2: %a"}
-; CHECK: !8 = distinct !{!8, !"hello2"}
-; CHECK: !9 = distinct !{!9, !8, !"hello2: %b"}
-; CHECK: !10 = distinct !{!10, !11, !"hello: %a"}
-; CHECK: !11 = distinct !{!11, !"hello"}
-; CHECK: !12 = !{!7}
-; CHECK: !13 = !{!9, !10}
-; CHECK: !14 = !{!9}
-; CHECK: !15 = !{!7, !10}
-; CHECK: !16 = !{!10}
+; CHECK: !6 = !{!7}
+; CHECK: !7 = distinct !{!7, !8, !"hello: %a"}
+; CHECK: !8 = distinct !{!8, !"hello"}
+; CHECK: !9 = !{!10, !12, !7}
+; CHECK: !10 = distinct !{!10, !11, !"hello2: %a"}
+; CHECK: !11 = distinct !{!11, !"hello2"}
+; CHECK: !12 = distinct !{!12, !11, !"hello2: %b"}
+; CHECK: !13 = !{!10}
+; CHECK: !14 = !{!12, !7}
+; CHECK: !15 = !{!12}
+; CHECK: !16 = !{!10, !7}
 ; CHECK: !17 = !{!18, !20}
 ; CHECK: !18 = distinct !{!18, !19, !"hello2: %a"}
 ; CHECK: !19 = distinct !{!19, !"hello2"}
 ; CHECK: !20 = distinct !{!20, !19, !"hello2: %b"}
-; CHECK: !21 = !{!18, !10}
+; CHECK: !21 = !{!18, !7}
 ; CHECK: !22 = !{!20}
-; CHECK: !23 = !{!20, !10}
+; CHECK: !23 = !{!20, !7}
 ; CHECK: !24 = !{!18}
-


        


More information about the llvm-commits mailing list