[llvm] 8e91154 - [MemorySSA] Make MemoryLocation unknown when phi translation cannot be performed.

Alina Sbirlea via llvm-commits llvm-commits at lists.llvm.org
Tue May 5 13:33:46 PDT 2020


Author: Alina Sbirlea
Date: 2020-05-05T13:32:32-07:00
New Revision: 8e911545d68ce54a104fafb5aaf7ffdc663c9cd4

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

LOG: [MemorySSA] Make MemoryLocation unknown when phi translation cannot be performed.

Summary: When phi translation cannot be performed, be conservative and make the MemoryLocation unknown.

Reviewers: george.burgess.iv

Subscribers: Prazek, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D79386

Added: 
    

Modified: 
    llvm/include/llvm/Analysis/MemoryLocation.h
    llvm/include/llvm/Analysis/MemorySSA.h
    llvm/test/Analysis/MemorySSA/phi-translation.ll

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/Analysis/MemoryLocation.h b/llvm/include/llvm/Analysis/MemoryLocation.h
index 446041119c80..9e5e43bbd5f5 100644
--- a/llvm/include/llvm/Analysis/MemoryLocation.h
+++ b/llvm/include/llvm/Analysis/MemoryLocation.h
@@ -205,6 +205,8 @@ class MemoryLocation {
   /// member is null if that kind of information is unavailable).
   AAMDNodes AATags;
 
+  void print(raw_ostream &OS) const { OS << *Ptr << " " << Size << "\n"; }
+
   /// Return a location with information about the memory reference by the given
   /// instruction.
   static MemoryLocation get(const LoadInst *LI);

diff  --git a/llvm/include/llvm/Analysis/MemorySSA.h b/llvm/include/llvm/Analysis/MemorySSA.h
index 24b806b2f498..5ce2b3fd047f 100644
--- a/llvm/include/llvm/Analysis/MemorySSA.h
+++ b/llvm/include/llvm/Analysis/MemorySSA.h
@@ -1228,6 +1228,9 @@ class upward_defs_iterator
           CurrentPair.second = Location.getWithNewPtr(Translator.getAddr());
           return;
         }
+      } else {
+        CurrentPair.second = Location.getWithNewSize(LocationSize::unknown());
+        return;
       }
     }
     CurrentPair.second = Location;

diff  --git a/llvm/test/Analysis/MemorySSA/phi-translation.ll b/llvm/test/Analysis/MemorySSA/phi-translation.ll
index 4d8111654d56..588b018fdd0d 100644
--- a/llvm/test/Analysis/MemorySSA/phi-translation.ll
+++ b/llvm/test/Analysis/MemorySSA/phi-translation.ll
@@ -235,3 +235,55 @@ for.inc:                                          ; preds = %for.body, %if.then
   %m_i_size.1 = phi i32 [ %m_i_size.022, %if.then ], [ %mul, %for.body ]
   br i1 %cmp1, label %for.body, label %for.cond.cleanup
 }
+
+
+%ArrayType = type { [2 x i64] }
+%StructOverArrayType = type { %ArrayType }
+%BigStruct = type { i8, i8, i8, i8, i8, i8, i8, %ArrayType, %ArrayType}
+
+; CHECK-LABEL: define void @use_not_optimized_due_to_backedge_unknown
+define void @use_not_optimized_due_to_backedge_unknown(%BigStruct* %this) {
+entry:
+  %eval_left_dims = alloca %StructOverArrayType, align 8
+  %tmp0 = bitcast %StructOverArrayType* %eval_left_dims to i8*
+  %eval_right_dims = alloca %StructOverArrayType, align 8
+  %tmp1 = bitcast %StructOverArrayType* %eval_right_dims to i8*
+  %lhs_strides = alloca %ArrayType, align 8
+  %rhs_strides = alloca %ArrayType, align 8
+  br label %for.body.preheader
+
+for.body.preheader:                               ; preds = %entry
+  %arrayidx.i527 = getelementptr inbounds %BigStruct, %BigStruct* %this, i64 0, i32 7, i32 0, i64 0
+; CHECK: 1 = MemoryDef(liveOnEntry)
+; CHECK-NEXT: store i64 1, i64* %arrayidx.i527, align 8
+  store i64 1, i64* %arrayidx.i527, align 8
+  %arrayidx.i528 = getelementptr inbounds %BigStruct, %BigStruct* %this, i64 0, i32 8, i32 0, i64 0
+; CHECK: 2 = MemoryDef(1)
+; CHECK-NEXT: store i64 1, i64* %arrayidx.i528, align 8
+  store i64 1, i64* %arrayidx.i528, align 8
+  br label %for.main.body
+
+for.main.body:               ; preds = %if.end220.if.then185_crit_edge, %for.body.preheader
+; CHECK: 4 = MemoryPhi({for.body.preheader,2},{if.end220.if.then185_crit_edge,3})
+; CHECK-NEXT: %nocontract_idx.0656 = phi i64 [ 0, %for.body.preheader ], [ 1, %if.end220.if.then185_crit_edge ]
+  %nocontract_idx.0656 = phi i64 [ 0, %for.body.preheader ], [ 1, %if.end220.if.then185_crit_edge ]
+  %add199 = add nuw nsw i64 %nocontract_idx.0656, 1
+  %cmp200 = icmp eq i64 %nocontract_idx.0656, 0
+  %arrayidx.i559 = getelementptr inbounds %BigStruct, %BigStruct* %this, i64 0, i32 7, i32 0, i64 %nocontract_idx.0656
+; CHECK: MemoryUse(4) MayAlias
+; CHECK-NEXT: %tmp21 = load i64, i64* %arrayidx.i559, align 8
+  %tmp21 = load i64, i64* %arrayidx.i559, align 8
+  %mul206 = mul nsw i64 %tmp21, %tmp21
+  br i1 %cmp200, label %if.end220.if.then185_crit_edge, label %the.end
+
+if.end220.if.then185_crit_edge:                   ; preds = %for.main.body
+  %arrayidx.i571 = getelementptr inbounds %BigStruct, %BigStruct* %this, i64 0, i32 7, i32 0, i64 %add199
+; CHECK: 3 = MemoryDef(4)
+; CHECK-NEXT: store i64 %mul206, i64* %arrayidx.i571, align 8
+  store i64 %mul206, i64* %arrayidx.i571, align 8
+  br label %for.main.body
+
+the.end:                            ; preds = %for.main.body
+  ret void
+
+}


        


More information about the llvm-commits mailing list