[llvm] da41cfd - Add test coverage for D109917 and variants

Philip Reames via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 22 19:38:56 PST 2021


Author: Philip Reames
Date: 2021-12-22T19:38:40-08:00
New Revision: da41cfddcad6740d2867ae0725110b77abc3a5ad

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

LOG: Add test coverage for D109917 and variants

Added: 
    

Modified: 
    llvm/test/Transforms/InstCombine/sink_sideeffecting_instruction.ll

Removed: 
    


################################################################################
diff  --git a/llvm/test/Transforms/InstCombine/sink_sideeffecting_instruction.ll b/llvm/test/Transforms/InstCombine/sink_sideeffecting_instruction.ll
index aed7db49b5fd2..791d4d9b2da8b 100644
--- a/llvm/test/Transforms/InstCombine/sink_sideeffecting_instruction.ll
+++ b/llvm/test/Transforms/InstCombine/sink_sideeffecting_instruction.ll
@@ -2,21 +2,21 @@
 ; RUN: opt -instcombine -S < %s | FileCheck %s
 
 ; Function Attrs: noinline uwtable
-define dso_local i32 @foo(i32* nocapture writeonly %arg) local_unnamed_addr #0 {
+define i32 @foo(i32* nocapture writeonly %arg) {
 ; CHECK-LABEL: @foo(
 ; CHECK-NEXT:  bb:
-; CHECK-NEXT:    [[VAR:%.*]] = call i32 @baz() #[[ATTR2:[0-9]+]]
-; CHECK-NEXT:    store i32 [[VAR]], i32* [[ARG:%.*]], align 4, !tbaa [[TBAA0:![0-9]+]]
-; CHECK-NEXT:    [[VAR1:%.*]] = call i32 @baz() #[[ATTR2]]
+; CHECK-NEXT:    [[VAR:%.*]] = call i32 @baz()
+; CHECK-NEXT:    store i32 [[VAR]], i32* [[ARG:%.*]], align 4
+; CHECK-NEXT:    [[VAR1:%.*]] = call i32 @baz()
 ; CHECK-NEXT:    ret i32 [[VAR1]]
 ;
 bb:
   %var = call i32 @baz()
-  store i32 %var, i32* %arg, align 4, !tbaa !2
+  store i32 %var, i32* %arg, align 4
   %var1 = call i32 @baz()
   ret i32 %var1
 }
-declare dso_local i32 @baz() local_unnamed_addr
+declare i32 @baz()
 
 ; Function Attrs: uwtable
 ; This is an equivalent IR for a c-style example with a large function (foo)
@@ -44,7 +44,7 @@ declare dso_local i32 @baz() local_unnamed_addr
 ; }
 
 ; TODO: We should be able to sink the second call @foo at bb5 down to bb_crit_edge
-define dso_local i32 @test() local_unnamed_addr #2 {
+define i32 @test() {
 ; CHECK-LABEL: @test(
 ; CHECK-NEXT:  bb:
 ; CHECK-NEXT:    [[VAR:%.*]] = alloca i32, align 4
@@ -57,7 +57,7 @@ define dso_local i32 @test() local_unnamed_addr #2 {
 ; CHECK:       bb5:
 ; CHECK-NEXT:    [[VAR6:%.*]] = bitcast i32* [[VAR1]] to i8*
 ; CHECK-NEXT:    call void @llvm.lifetime.start.p0i8(i64 4, i8* nonnull [[VAR6]])
-; CHECK-NEXT:    [[VAR8:%.*]] = load i32, i32* [[VAR]], align 4, !tbaa [[TBAA0]]
+; CHECK-NEXT:    [[VAR8:%.*]] = load i32, i32* [[VAR]], align 4
 ; CHECK-NEXT:    [[VAR9:%.*]] = icmp eq i32 [[VAR8]], 0
 ; CHECK-NEXT:    [[VAR7:%.*]] = call i32 @foo(i32* nonnull writeonly [[VAR1]])
 ; CHECK-NEXT:    br i1 [[VAR9]], label [[BB10:%.*]], label [[BB_CRIT_EDGE:%.*]]
@@ -87,7 +87,7 @@ bb:
 bb5:                                              ; preds = %bb
   %var6 = bitcast i32* %var1 to i8*
   call void @llvm.lifetime.start.p0i8(i64 4, i8* nonnull %var6) #4
-  %var8 = load i32, i32* %var, align 4, !tbaa !2
+  %var8 = load i32, i32* %var, align 4
   %var9 = icmp eq i32 %var8, 0
   %var7 = call i32 @foo(i32* nonnull writeonly %var1)
   br i1 %var9, label %bb10, label %bb_crit_edge
@@ -110,18 +110,100 @@ bb14:                                             ; preds = %bb12, %bb
   ret i32 %var15
 }
 
+declare i32 @unknown(i32* %dest)
+
+define i32 @sink_to_use(i1 %c) {
+; CHECK-LABEL: @sink_to_use(
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:    [[VAR:%.*]] = alloca i32, align 4
+; CHECK-NEXT:    [[VAR3:%.*]] = call i32 @unknown(i32* nonnull [[VAR]]) #[[ATTR1:[0-9]+]]
+; CHECK-NEXT:    br i1 [[C:%.*]], label [[EARLY_RETURN:%.*]], label [[USE_BLOCK:%.*]]
+; CHECK:       early_return:
+; CHECK-NEXT:    ret i32 0
+; CHECK:       use_block:
+; CHECK-NEXT:    ret i32 [[VAR3]]
+;
+entry:
+  %var = alloca i32, align 4
+  %var3 = call i32 @unknown(i32* %var) argmemonly nounwind willreturn
+  br i1 %c, label %early_return, label %use_block
+
+early_return:
+  ret i32 0
+
+use_block:
+  ret i32 %var3
+}
+
+define i32 @neg_infinite_loop(i1 %c) {
+; CHECK-LABEL: @neg_infinite_loop(
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:    [[VAR:%.*]] = alloca i32, align 4
+; CHECK-NEXT:    [[VAR3:%.*]] = call i32 @unknown(i32* nonnull [[VAR]]) #[[ATTR2:[0-9]+]]
+; CHECK-NEXT:    br i1 [[C:%.*]], label [[EARLY_RETURN:%.*]], label [[USE_BLOCK:%.*]]
+; CHECK:       early_return:
+; CHECK-NEXT:    ret i32 0
+; CHECK:       use_block:
+; CHECK-NEXT:    ret i32 [[VAR3]]
+;
+entry:
+  %var = alloca i32, align 4
+  %var3 = call i32 @unknown(i32* %var) argmemonly nounwind
+  br i1 %c, label %early_return, label %use_block
+
+early_return:
+  ret i32 0
+
+use_block:
+  ret i32 %var3
+}
+
+define i32 @neg_throw(i1 %c) {
+; CHECK-LABEL: @neg_throw(
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:    [[VAR:%.*]] = alloca i32, align 4
+; CHECK-NEXT:    [[VAR3:%.*]] = call i32 @unknown(i32* nonnull [[VAR]]) #[[ATTR3:[0-9]+]]
+; CHECK-NEXT:    br i1 [[C:%.*]], label [[EARLY_RETURN:%.*]], label [[USE_BLOCK:%.*]]
+; CHECK:       early_return:
+; CHECK-NEXT:    ret i32 0
+; CHECK:       use_block:
+; CHECK-NEXT:    ret i32 [[VAR3]]
+;
+entry:
+  %var = alloca i32, align 4
+  %var3 = call i32 @unknown(i32* %var) argmemonly willreturn
+  br i1 %c, label %early_return, label %use_block
+
+early_return:
+  ret i32 0
+
+use_block:
+  ret i32 %var3
+}
+
+define i32 @neg_unknown_write(i1 %c) {
+; CHECK-LABEL: @neg_unknown_write(
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:    [[VAR:%.*]] = alloca i32, align 4
+; CHECK-NEXT:    [[VAR3:%.*]] = call i32 @unknown(i32* nonnull [[VAR]]) #[[ATTR4:[0-9]+]]
+; CHECK-NEXT:    br i1 [[C:%.*]], label [[EARLY_RETURN:%.*]], label [[USE_BLOCK:%.*]]
+; CHECK:       early_return:
+; CHECK-NEXT:    ret i32 0
+; CHECK:       use_block:
+; CHECK-NEXT:    ret i32 [[VAR3]]
+;
+entry:
+  %var = alloca i32, align 4
+  %var3 = call i32 @unknown(i32* %var) nounwind willreturn
+  br i1 %c, label %early_return, label %use_block
+
+early_return:
+  ret i32 0
+
+use_block:
+  ret i32 %var3
+}
+
 declare i32 @bar()
-; Function Attrs: argmemonly nofree nosync nounwind willreturn
-declare void @llvm.lifetime.start.p0i8(i64 immarg, i8* nocapture) #3
-
-; Function Attrs: argmemonly nofree nosync nounwind willreturn
-declare void @llvm.lifetime.end.p0i8(i64 immarg, i8* nocapture) #3
-
-attributes #0 = { noinline uwtable argmemonly nounwind willreturn writeonly }
-attributes #3 = { argmemonly nofree nosync nounwind willreturn }
-!0 = !{i32 1, !"wchar_size", i32 4}
-!1 = !{!"clang version 10.0.0-4ubuntu1 "}
-!2 = !{!3, !3, i64 0}
-!3 = !{!"int", !4, i64 0}
-!4 = !{!"omnipotent char", !5, i64 0}
-!5 = !{!"Simple C++ TBAA"}
+declare void @llvm.lifetime.start.p0i8(i64 immarg, i8* nocapture)
+declare void @llvm.lifetime.end.p0i8(i64 immarg, i8* nocapture)


        


More information about the llvm-commits mailing list