[llvm] r354919 - [MemorySSA & SimpleLoopUnswitch] Update MemorySSA in ReplaceUsesOfWith.

Alina Sbirlea via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 26 11:44:53 PST 2019


Author: asbirlea
Date: Tue Feb 26 11:44:52 2019
New Revision: 354919

URL: http://llvm.org/viewvc/llvm-project?rev=354919&view=rev
Log:
[MemorySSA & SimpleLoopUnswitch] Update MemorySSA in ReplaceUsesOfWith.

SimpleLoopUnswitch must update MemorySSA when removing instructions.
Resolves PR39197.

Added:
    llvm/trunk/test/Analysis/MemorySSA/pr39197.ll
Modified:
    llvm/trunk/lib/Transforms/Scalar/LoopUnswitch.cpp

Modified: llvm/trunk/lib/Transforms/Scalar/LoopUnswitch.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/LoopUnswitch.cpp?rev=354919&r1=354918&r2=354919&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/LoopUnswitch.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/LoopUnswitch.cpp Tue Feb 26 11:44:52 2019
@@ -1404,8 +1404,8 @@ static void RemoveFromWorklist(Instructi
 /// When we find that I really equals V, remove I from the
 /// program, replacing all uses with V and update the worklist.
 static void ReplaceUsesOfWith(Instruction *I, Value *V,
-                              std::vector<Instruction*> &Worklist,
-                              Loop *L, LPPassManager *LPM) {
+                              std::vector<Instruction *> &Worklist, Loop *L,
+                              LPPassManager *LPM, MemorySSAUpdater *MSSAU) {
   LLVM_DEBUG(dbgs() << "Replace with '" << *V << "': " << *I << "\n");
 
   // Add uses to the worklist, which may be dead now.
@@ -1419,8 +1419,11 @@ static void ReplaceUsesOfWith(Instructio
   LPM->deleteSimpleAnalysisValue(I, L);
   RemoveFromWorklist(I, Worklist);
   I->replaceAllUsesWith(V);
-  if (!I->mayHaveSideEffects())
+  if (!I->mayHaveSideEffects()) {
+    if (MSSAU)
+      MSSAU->removeMemoryAccess(I);
     I->eraseFromParent();
+  }
   ++NumSimplify;
 }
 
@@ -1595,7 +1598,7 @@ void LoopUnswitch::SimplifyCode(std::vec
     // 'false'.  TODO: update the domtree properly so we can pass it here.
     if (Value *V = SimplifyInstruction(I, DL))
       if (LI->replacementPreservesLCSSAForm(I, V)) {
-        ReplaceUsesOfWith(I, V, Worklist, L, LPM);
+        ReplaceUsesOfWith(I, V, Worklist, L, LPM, MSSAU.get());
         continue;
       }
 
@@ -1615,7 +1618,8 @@ void LoopUnswitch::SimplifyCode(std::vec
 
         // Resolve any single entry PHI nodes in Succ.
         while (PHINode *PN = dyn_cast<PHINode>(Succ->begin()))
-          ReplaceUsesOfWith(PN, PN->getIncomingValue(0), Worklist, L, LPM);
+          ReplaceUsesOfWith(PN, PN->getIncomingValue(0), Worklist, L, LPM,
+                            MSSAU.get());
 
         // If Succ has any successors with PHI nodes, update them to have
         // entries coming from Pred instead of Succ.

Added: llvm/trunk/test/Analysis/MemorySSA/pr39197.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Analysis/MemorySSA/pr39197.ll?rev=354919&view=auto
==============================================================================
--- llvm/trunk/test/Analysis/MemorySSA/pr39197.ll (added)
+++ llvm/trunk/test/Analysis/MemorySSA/pr39197.ll Tue Feb 26 11:44:52 2019
@@ -0,0 +1,153 @@
+; RUN: opt -mtriple=s390x-linux-gnu -mcpu=z13 -enable-mssa-loop-dependency -verify-memoryssa -sroa -globalopt -functionattrs -simplifycfg -licm -loop-unswitch %s -S | FileCheck %s
+; REQUIRES: asserts
+
+target datalayout = "E-m:e-i1:8:16-i8:8:16-i64:64-f128:64-v128:64-a:8:16-n32:64"
+target triple = "s390x-ibm-linux"
+
+ at 0 = internal global i32 -9, align 4
+ at 1 = internal global i64 9, align 8
+ at g_1042 = external dso_local global [5 x i16], align 2
+
+; CHECK-LABEL: @main()
+; Function Attrs: nounwind
+define dso_local void @main() #0 {
+  call void @func_1()
+  unreachable
+}
+
+; Function Attrs: argmemonly nounwind
+declare void @llvm.lifetime.end.p0i8(i64, i8* nocapture) #1
+
+; Function Attrs: nounwind
+define dso_local void @func_1() #0 {
+  %1 = alloca i32*, align 8
+  %2 = call signext i32 @func_2()
+  %3 = icmp ne i32 %2, 0
+  br i1 %3, label %4, label %9
+
+; <label>:4:                                      ; preds = %0
+  %5 = load i16, i16* getelementptr inbounds ([5 x i16], [5 x i16]* @g_1042, i64 0, i64 0), align 2, !tbaa !1
+  %6 = zext i16 %5 to i64
+  %7 = load i64, i64* @1, align 8, !tbaa !5
+  %8 = and i64 %7, %6
+  store i64 %8, i64* @1, align 8, !tbaa !5
+  call void @llvm.lifetime.end.p0i8(i64 4, i8* undef) #2
+  unreachable
+
+; <label>:9:                                      ; preds = %0
+  store i32* @0, i32** %1, align 8, !tbaa !7
+  br label %10
+
+; <label>:10:                                     ; preds = %23, %9
+  %11 = load i64, i64* @1, align 8, !tbaa !5
+  %12 = icmp eq i64 %11, 65535
+  br i1 %12, label %13, label %14
+
+; <label>:13:                                     ; preds = %10
+  store i32* null, i32** %1, align 8, !tbaa !7
+  br label %14
+
+; <label>:14:                                     ; preds = %13, %10
+  %15 = load i32*, i32** %1, align 8, !tbaa !7
+  %16 = load i32, i32* %15, align 4, !tbaa !9
+  %17 = trunc i32 %16 to i16
+  %18 = call signext i16 @safe_sub_func_int16_t_s_s(i16 signext %17)
+  %19 = sext i16 %18 to i32
+  %20 = icmp ne i32 %19, 0
+  br i1 %20, label %23, label %21
+
+; <label>:21:                                     ; preds = %14
+  %22 = load volatile i8, i8* null, align 1, !tbaa !11
+  br label %23
+
+; <label>:23:                                     ; preds = %21, %14
+  br label %10
+}
+
+; Function Attrs: nounwind
+declare dso_local signext i32 @func_2() #0
+
+; Function Attrs: nounwind
+define dso_local void @safe_sub_func_uint8_t_u_u() #0 {
+  ret void
+}
+
+; Function Attrs: nounwind
+define dso_local void @safe_add_func_int64_t_s_s() #0 {
+  ret void
+}
+
+; Function Attrs: nounwind
+define dso_local void @safe_rshift_func_int16_t_s_u() #0 {
+  ret void
+}
+
+; Function Attrs: nounwind
+define dso_local void @safe_div_func_uint8_t_u_u() #0 {
+  ret void
+}
+
+; Function Attrs: nounwind
+define dso_local void @safe_mul_func_uint16_t_u_u() #0 {
+  ret void
+}
+
+; Function Attrs: nounwind
+define dso_local void @safe_mul_func_int16_t_s_s() #0 {
+  ret void
+}
+
+; Function Attrs: nounwind
+define dso_local void @safe_div_func_int32_t_s_s() #0 {
+  ret void
+}
+
+; Function Attrs: nounwind
+define dso_local signext i16 @safe_sub_func_int16_t_s_s(i16 signext) #0 {
+  %2 = alloca i16, align 2
+  store i16 %0, i16* %2, align 2, !tbaa !1
+  %3 = load i16, i16* %2, align 2, !tbaa !1
+  %4 = sext i16 %3 to i32
+  %5 = sub nsw i32 %4, 0
+  %6 = trunc i32 %5 to i16
+  ret i16 %6
+}
+
+; Function Attrs: nounwind
+define dso_local void @safe_add_func_uint16_t_u_u() #0 {
+  ret void
+}
+
+; Function Attrs: nounwind
+define dso_local void @safe_div_func_int8_t_s_s() #0 {
+  ret void
+}
+
+; Function Attrs: nounwind
+define dso_local void @safe_add_func_int16_t_s_s() #0 {
+  ret void
+}
+
+; Function Attrs: nounwind
+define dso_local void @safe_add_func_uint8_t_u_u() #0 {
+  ret void
+}
+
+attributes #0 = { nounwind "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="z13" "target-features"="+transactional-execution,+vector" "unsafe-fp-math"="false" "use-soft-float"="false" }
+attributes #1 = { argmemonly nounwind }
+attributes #2 = { nounwind }
+
+!llvm.ident = !{!0}
+
+!0 = !{!"clang version 8.0.0 (http://llvm.org/git/clang.git 7cda4756fc9713d98fd3513b8df172700f267bad) (http://llvm.org/git/llvm.git 199c0d32e96b646bd8cf6beeaf0f99f8a434b56a)"}
+!1 = !{!2, !2, i64 0}
+!2 = !{!"short", !3, i64 0}
+!3 = !{!"omnipotent char", !4, i64 0}
+!4 = !{!"Simple C/C++ TBAA"}
+!5 = !{!6, !6, i64 0}
+!6 = !{!"long", !3, i64 0}
+!7 = !{!8, !8, i64 0}
+!8 = !{!"any pointer", !3, i64 0}
+!9 = !{!10, !10, i64 0}
+!10 = !{!"int", !3, i64 0}
+!11 = !{!3, !3, i64 0}




More information about the llvm-commits mailing list