[llvm] 1b84934 - [DSE] Add more tests for read clobber location (NFC)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Thu Dec 17 12:03:12 PST 2020
Author: Nikita Popov
Date: 2020-12-17T21:03:00+01:00
New Revision: 1b84934f908d7ab04443f2d442a19d058aadc2ed
URL: https://github.com/llvm/llvm-project/commit/1b84934f908d7ab04443f2d442a19d058aadc2ed
DIFF: https://github.com/llvm/llvm-project/commit/1b84934f908d7ab04443f2d442a19d058aadc2ed.diff
LOG: [DSE] Add more tests for read clobber location (NFC)
Added:
llvm/test/Transforms/DeadStoreElimination/MSSA/scoped-noalias.ll
Modified:
llvm/test/Transforms/DeadStoreElimination/MSSA/overlap.ll
Removed:
################################################################################
diff --git a/llvm/test/Transforms/DeadStoreElimination/MSSA/overlap.ll b/llvm/test/Transforms/DeadStoreElimination/MSSA/overlap.ll
index 31bb3234dc42..9d20f80f5099 100644
--- a/llvm/test/Transforms/DeadStoreElimination/MSSA/overlap.ll
+++ b/llvm/test/Transforms/DeadStoreElimination/MSSA/overlap.ll
@@ -6,14 +6,14 @@ declare void @use(i64*)
define void @test1() {
; CHECK-LABEL: @test1(
-; CHECK-NEXT: [[A:%.*]] = alloca i64
+; CHECK-NEXT: [[A:%.*]] = alloca i64, align 8
; CHECK-NEXT: call void @use(i64* [[A]])
; CHECK-NEXT: [[PTR1:%.*]] = bitcast i64* [[A]] to i8*
; CHECK-NEXT: [[PTR2:%.*]] = getelementptr i8, i8* [[PTR1]], i32 1
-; CHECK-NEXT: store i8 10, i8* [[PTR1]]
-; CHECK-NEXT: store i8 20, i8* [[PTR2]]
-; CHECK-NEXT: [[LV:%.*]] = load i64, i64* [[A]]
-; CHECK-NEXT: store i8 0, i8* [[PTR1]]
+; CHECK-NEXT: store i8 10, i8* [[PTR1]], align 1
+; CHECK-NEXT: store i8 20, i8* [[PTR2]], align 1
+; CHECK-NEXT: [[LV:%.*]] = load i64, i64* [[A]], align 4
+; CHECK-NEXT: store i8 0, i8* [[PTR1]], align 1
; CHECK-NEXT: call void @use(i64* [[A]])
; CHECK-NEXT: ret void
;
@@ -33,18 +33,18 @@ define void @test1() {
define void @test2() {
; CHECK-LABEL: @test2(
-; CHECK-NEXT: [[A:%.*]] = alloca i64
+; CHECK-NEXT: [[A:%.*]] = alloca i64, align 8
; CHECK-NEXT: call void @use(i64* [[A]])
; CHECK-NEXT: [[PTR1:%.*]] = bitcast i64* [[A]] to i8*
; CHECK-NEXT: [[PTR2:%.*]] = getelementptr i8, i8* [[PTR1]], i32 1
-; CHECK-NEXT: store i8 10, i8* [[PTR1]]
-; CHECK-NEXT: store i8 20, i8* [[PTR2]]
+; CHECK-NEXT: store i8 10, i8* [[PTR1]], align 1
+; CHECK-NEXT: store i8 20, i8* [[PTR2]], align 1
; CHECK-NEXT: br i1 undef, label [[BB1:%.*]], label [[END:%.*]]
; CHECK: bb1:
-; CHECK-NEXT: [[LV:%.*]] = load i64, i64* [[A]]
+; CHECK-NEXT: [[LV:%.*]] = load i64, i64* [[A]], align 4
; CHECK-NEXT: br label [[END]]
; CHECK: end:
-; CHECK-NEXT: store i8 0, i8* [[PTR1]]
+; CHECK-NEXT: store i8 0, i8* [[PTR1]], align 1
; CHECK-NEXT: call void @use(i64* [[A]])
; CHECK-NEXT: ret void
;
@@ -66,3 +66,33 @@ end:
call void @use(i64* %a)
ret void
}
+
+; TODO: The store to %a0 is dead, because only %a1 is read later.
+define void @test3(i1 %c) {
+; CHECK-LABEL: @test3(
+; CHECK-NEXT: [[A:%.*]] = alloca [2 x i8], align 1
+; CHECK-NEXT: [[A0:%.*]] = getelementptr [2 x i8], [2 x i8]* [[A]], i32 0, i32 0
+; CHECK-NEXT: [[A1:%.*]] = getelementptr [2 x i8], [2 x i8]* [[A]], i32 0, i32 1
+; CHECK-NEXT: store i8 1, i8* [[A0]], align 1
+; CHECK-NEXT: br i1 [[C:%.*]], label [[IF:%.*]], label [[ELSE:%.*]]
+; CHECK: if:
+; CHECK-NEXT: store [2 x i8] zeroinitializer, [2 x i8]* [[A]], align 1
+; CHECK-NEXT: br label [[ELSE]]
+; CHECK: else:
+; CHECK-NEXT: [[TMP1:%.*]] = load i8, i8* [[A1]], align 1
+; CHECK-NEXT: ret void
+;
+ %a = alloca [2 x i8]
+ %a0 = getelementptr [2 x i8], [2 x i8]* %a, i32 0, i32 0
+ %a1 = getelementptr [2 x i8], [2 x i8]* %a, i32 0, i32 1
+ store i8 1, i8* %a0
+ br i1 %c, label %if, label %else
+
+if:
+ store [2 x i8] zeroinitializer, [2 x i8]* %a
+ br label %else
+
+else:
+ load i8, i8* %a1
+ ret void
+}
diff --git a/llvm/test/Transforms/DeadStoreElimination/MSSA/scoped-noalias.ll b/llvm/test/Transforms/DeadStoreElimination/MSSA/scoped-noalias.ll
new file mode 100644
index 000000000000..b2e626250817
--- /dev/null
+++ b/llvm/test/Transforms/DeadStoreElimination/MSSA/scoped-noalias.ll
@@ -0,0 +1,34 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt -S -scoped-noalias-aa -dse < %s | FileCheck %s
+
+; Assume that %p1 != %p2 if and only if %c is true. In that case the noalias
+; metadata is correct, but the first store cannot be eliminated, as it may be
+; read-clobbered by the load.
+; TODO The store is incorrectly eliminated.
+define void @test(i1 %c, i8* %p1, i8* %p2) {
+; CHECK-LABEL: @test(
+; CHECK-NEXT: [[TMP1:%.*]] = load i8, i8* [[P2:%.*]], align 1, !alias.scope !0
+; CHECK-NEXT: br i1 [[C:%.*]], label [[IF:%.*]], label [[ELSE:%.*]]
+; CHECK: if:
+; CHECK-NEXT: store i8 1, i8* [[P1:%.*]], align 1, !noalias !0
+; CHECK-NEXT: ret void
+; CHECK: else:
+; CHECK-NEXT: store i8 2, i8* [[P1]], align 1
+; CHECK-NEXT: ret void
+;
+ store i8 0, i8* %p1
+ load i8, i8* %p2, !alias.scope !2
+ br i1 %c, label %if, label %else
+
+if:
+ store i8 1, i8* %p1, !noalias !2
+ ret void
+
+else:
+ store i8 2, i8* %p1
+ ret void
+}
+
+!0 = !{!0}
+!1 = !{!1, !0}
+!2 = !{!1}
More information about the llvm-commits
mailing list