[llvm] 9c00afe - [DSE] Add test case with multiple inbounds stores, followed by OOB.
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Fri Nov 12 01:40:23 PST 2021
Author: Florian Hahn
Date: 2021-11-12T09:40:03Z
New Revision: 9c00afe926e9f22f4e0cd92d88068c8a6ed769d0
URL: https://github.com/llvm/llvm-project/commit/9c00afe926e9f22f4e0cd92d88068c8a6ed769d0
DIFF: https://github.com/llvm/llvm-project/commit/9c00afe926e9f22f4e0cd92d88068c8a6ed769d0.diff
LOG: [DSE] Add test case with multiple inbounds stores, followed by OOB.
This patch extends the existing out-of-bounds store tests with a case
with a bigger object and multiple inbounds stores, followed by an OOB
store. The OOB store is not used to remove the inbounds stores in this
case at the moment.
Added:
Modified:
llvm/test/Transforms/DeadStoreElimination/out-of-bounds-stores.ll
Removed:
################################################################################
diff --git a/llvm/test/Transforms/DeadStoreElimination/out-of-bounds-stores.ll b/llvm/test/Transforms/DeadStoreElimination/out-of-bounds-stores.ll
index 925ab4e99597d..949ab781b4961 100644
--- a/llvm/test/Transforms/DeadStoreElimination/out-of-bounds-stores.ll
+++ b/llvm/test/Transforms/DeadStoreElimination/out-of-bounds-stores.ll
@@ -1,7 +1,7 @@
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt -dse -S %s | FileCheck %s
-declare void @use(i32)
+declare void @use_pointer(i32*)
; Out-of-bounds stores can be considered killing any other stores to the same
; object in the same BB, because they are UB and guaranteed to execute. Note
@@ -10,9 +10,10 @@ declare void @use(i32)
define i32 @test_out_of_bounds_store_local(i1 %c) {
; CHECK-LABEL: @test_out_of_bounds_store_local(
; CHECK-NEXT: [[D:%.*]] = alloca [1 x i32], align 4
-; CHECK-NEXT: [[ARRAYIDX1:%.*]] = getelementptr inbounds [1 x i32], [1 x i32]* [[D]], i64 0, i64 0
-; CHECK-NEXT: [[LV1:%.*]] = load i32, i32* [[ARRAYIDX1]], align 4
-; CHECK-NEXT: call void @use(i32 [[LV1]])
+; CHECK-NEXT: [[ARRAYIDX_1:%.*]] = getelementptr inbounds [1 x i32], [1 x i32]* [[D]], i64 0, i64 1
+; CHECK-NEXT: store i32 20, i32* [[ARRAYIDX_1]], align 4
+; CHECK-NEXT: [[BC:%.*]] = bitcast [1 x i32]* [[D]] to i32*
+; CHECK-NEXT: call void @use_pointer(i32* [[BC]])
; CHECK-NEXT: ret i32 0
;
%d = alloca [1 x i32], align 4
@@ -20,9 +21,37 @@ define i32 @test_out_of_bounds_store_local(i1 %c) {
store i32 10, i32* %arrayidx, align 4
%arrayidx.1 = getelementptr inbounds [1 x i32], [1 x i32]* %d, i64 0, i64 1
store i32 20, i32* %arrayidx.1, align 4
- %arrayidx1 = getelementptr inbounds [1 x i32], [1 x i32]* %d, i64 0, i64 0
- %lv1 = load i32, i32* %arrayidx1, align 4
- call void @use(i32 %lv1)
+ %bc = bitcast [1 x i32]* %d to i32*
+ call void @use_pointer(i32* %bc)
+ ret i32 0
+}
+
+; Similar to @test_out_of_bounds_store_local, but with multiple in-bounds
+; stores to a larger object, followed by an out-of-bounds store.
+; FIXME: the 2 inbounds stores could be removed by applying the same
+; reasoning as for @test_out_of_bounds_store_local.
+define i32 @test_out_of_bounds_store_local_larger_object(i1 %c) {
+; CHECK-LABEL: @test_out_of_bounds_store_local_larger_object(
+; CHECK-NEXT: [[D:%.*]] = alloca [2 x i32], align 4
+; CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds [2 x i32], [2 x i32]* [[D]], i64 0, i64 0
+; CHECK-NEXT: store i32 10, i32* [[ARRAYIDX]], align 4
+; CHECK-NEXT: [[ARRAYIDX_1:%.*]] = getelementptr inbounds [2 x i32], [2 x i32]* [[D]], i64 0, i64 1
+; CHECK-NEXT: store i32 20, i32* [[ARRAYIDX_1]], align 4
+; CHECK-NEXT: [[ARRAYIDX_2:%.*]] = getelementptr inbounds [2 x i32], [2 x i32]* [[D]], i64 0, i64 2
+; CHECK-NEXT: store i32 30, i32* [[ARRAYIDX_2]], align 4
+; CHECK-NEXT: [[BC:%.*]] = bitcast [2 x i32]* [[D]] to i32*
+; CHECK-NEXT: call void @use_pointer(i32* [[BC]])
+; CHECK-NEXT: ret i32 0
+;
+ %d = alloca [2 x i32], align 4
+ %arrayidx = getelementptr inbounds [2 x i32], [2 x i32]* %d, i64 0, i64 0
+ store i32 10, i32* %arrayidx, align 4
+ %arrayidx.1 = getelementptr inbounds [2 x i32], [2 x i32]* %d, i64 0, i64 1
+ store i32 20, i32* %arrayidx.1, align 4
+ %arrayidx.2 = getelementptr inbounds [2 x i32], [2 x i32]* %d, i64 0, i64 2
+ store i32 30, i32* %arrayidx.2, align 4
+ %bc = bitcast [2 x i32]* %d to i32*
+ call void @use_pointer(i32* %bc)
ret i32 0
}
@@ -44,9 +73,8 @@ define i32 @test_out_of_bounds_store_nonlocal(i1 %c) {
; CHECK: for.body.1:
; CHECK-NEXT: ret i32 1
; CHECK: for.end:
-; CHECK-NEXT: [[ARRAYIDX1:%.*]] = getelementptr inbounds [1 x i32], [1 x i32]* [[D]], i64 0, i64 0
-; CHECK-NEXT: [[LV1:%.*]] = load i32, i32* [[ARRAYIDX1]], align 4
-; CHECK-NEXT: call void @use(i32 [[LV1]])
+; CHECK-NEXT: [[BC:%.*]] = bitcast [1 x i32]* [[D]] to i32*
+; CHECK-NEXT: call void @use_pointer(i32* [[BC]])
; CHECK-NEXT: ret i32 0
;
%d = alloca [1 x i32], align 4
@@ -66,8 +94,7 @@ for.body.1: ; preds = %for.inc
ret i32 1
for.end: ; preds = %for.inc
- %arrayidx1 = getelementptr inbounds [1 x i32], [1 x i32]* %d, i64 0, i64 0
- %lv1 = load i32, i32* %arrayidx1, align 4
- call void @use(i32 %lv1)
+ %bc = bitcast [1 x i32]* %d to i32*
+ call void @use_pointer(i32* %bc)
ret i32 0
}
More information about the llvm-commits
mailing list