[llvm] cb9528a - [DSE] Add another test cases with loop carried dependence.

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 16 06:51:06 PDT 2020


Author: Florian Hahn
Date: 2020-09-16T14:50:35+01:00
New Revision: cb9528a0420e01caf7f3dc8288a11258fcf1425d

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

LOG: [DSE] Add another test cases with loop carried dependence.

Added: 
    

Modified: 
    llvm/test/Transforms/DeadStoreElimination/MSSA/multiblock-loop-carried-dependence.ll

Removed: 
    


################################################################################
diff  --git a/llvm/test/Transforms/DeadStoreElimination/MSSA/multiblock-loop-carried-dependence.ll b/llvm/test/Transforms/DeadStoreElimination/MSSA/multiblock-loop-carried-dependence.ll
index b168dcaa859e..b7a882a65bc1 100644
--- a/llvm/test/Transforms/DeadStoreElimination/MSSA/multiblock-loop-carried-dependence.ll
+++ b/llvm/test/Transforms/DeadStoreElimination/MSSA/multiblock-loop-carried-dependence.ll
@@ -1,6 +1,6 @@
 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
 
-; RUN: opt -dse -S %s | FileCheck %s
+; RUN: opt -dse -enable-dse-memoryssa -S %s | FileCheck %s
 
 target datalayout = "e-m:e-i64:64-n32:64-v256:256:256-v512:512:512"
 
@@ -141,3 +141,72 @@ exit:
 }
 
 declare void @llvm.lifetime.end.p0i8(i64 immarg, i8* nocapture)
+
+; Make sure `store i32 10, i32* %ptr.2` in %cond.store is not removed. The
+; stored value may be read by `%use = load i32, i32* %ptr.1` in a future
+; iteration.
+define void at test.3() {
+; CHECK-LABEL: @test.3(
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:    [[NODESTACK:%.*]] = alloca [12 x i32], align 4
+; CHECK-NEXT:    [[NODESTACK_CAST:%.*]] = bitcast [12 x i32]* [[NODESTACK]] to i8*
+; CHECK-NEXT:    [[C_1:%.*]] = call i1 @cond(i32 1)
+; CHECK-NEXT:    br i1 [[C_1]], label [[CLEANUP:%.*]], label [[LOOP_HEADER:%.*]]
+; CHECK:       loop.header:
+; CHECK-NEXT:    [[DEPTH_1:%.*]] = phi i32 [ [[DEPTH_1_BE:%.*]], [[LOOP_LATCH:%.*]] ], [ 3, [[ENTRY:%.*]] ]
+; CHECK-NEXT:    [[CMP:%.*]] = icmp sgt i32 [[DEPTH_1]], 0
+; CHECK-NEXT:    br i1 [[CMP]], label [[COND_READ:%.*]], label [[COND_STORE:%.*]]
+; CHECK:       cond.read:
+; CHECK-NEXT:    [[SUB:%.*]] = add nsw i32 [[DEPTH_1]], -3
+; CHECK-NEXT:    [[PTR_1:%.*]] = getelementptr inbounds [12 x i32], [12 x i32]* [[NODESTACK]], i32 0, i32 [[SUB]]
+; CHECK-NEXT:    [[USE:%.*]] = load i32, i32* [[PTR_1]], align 4
+; CHECK-NEXT:    [[C_2:%.*]] = call i1 @cond(i32 [[USE]])
+; CHECK-NEXT:    br i1 [[C_2]], label [[LOOP_LATCH]], label [[COND_STORE]]
+; CHECK:       cond.store:
+; CHECK-NEXT:    [[PTR_2:%.*]] = getelementptr inbounds [12 x i32], [12 x i32]* [[NODESTACK]], i32 0, i32 [[DEPTH_1]]
+; CHECK-NEXT:    store i32 10, i32* [[PTR_2]], align 4
+; CHECK-NEXT:    [[INC:%.*]] = add nsw i32 [[DEPTH_1]], 1
+; CHECK-NEXT:    [[C_3:%.*]] = call i1 @cond(i32 20)
+; CHECK-NEXT:    br i1 [[C_3]], label [[CLEANUP]], label [[LOOP_LATCH]]
+; CHECK:       loop.latch:
+; CHECK-NEXT:    [[DEPTH_1_BE]] = phi i32 [ [[SUB]], [[COND_READ]] ], [ [[INC]], [[COND_STORE]] ]
+; CHECK-NEXT:    br label [[LOOP_HEADER]]
+; CHECK:       cleanup:
+; CHECK-NEXT:    call void @llvm.lifetime.end.p0i8(i64 48, i8* nonnull [[NODESTACK_CAST]])
+; CHECK-NEXT:    ret void
+;
+entry:
+  %nodeStack = alloca [12 x i32], align 4
+  %nodeStack.cast = bitcast [12 x i32]* %nodeStack to i8*
+  %c.1 = call i1 @cond(i32 1)
+  br i1 %c.1, label %cleanup, label %loop.header
+
+loop.header:                                       ; preds = %entry, %while.cond.backedge
+  %depth.1 = phi i32 [ %depth.1.be, %loop.latch ], [ 3, %entry ]
+  %cmp = icmp sgt i32 %depth.1, 0
+  br i1 %cmp, label %cond.read, label %cond.store
+
+cond.read:                                        ; preds = %while.cond
+  %sub = add nsw i32 %depth.1, -3
+  %ptr.1 = getelementptr inbounds [12 x i32], [12 x i32]* %nodeStack, i32 0, i32 %sub
+  %use = load i32, i32* %ptr.1, align 4
+  %c.2 = call i1 @cond(i32 %use)
+  br i1 %c.2, label %loop.latch, label %cond.store
+
+cond.store:
+  %ptr.2 = getelementptr inbounds [12 x i32], [12 x i32]* %nodeStack, i32 0, i32 %depth.1
+  store i32 10, i32* %ptr.2, align 4
+  %inc = add nsw i32 %depth.1, 1
+  %c.3 = call i1 @cond(i32 20)
+  br i1 %c.3, label %cleanup, label %loop.latch
+
+loop.latch:
+  %depth.1.be = phi i32 [ %sub, %cond.read ], [ %inc, %cond.store ]
+  br label %loop.header
+
+cleanup:                                          ; preds = %while.body, %while.end, %entry
+  call void @llvm.lifetime.end.p0i8(i64 48, i8* nonnull %nodeStack.cast) #3
+  ret void
+}
+
+declare i1 @cond(i32)


        


More information about the llvm-commits mailing list