[llvm] ce654f4 - [SCCP] Add test where dereferenceable ptr is replaced with un-dereferenceable one
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 3 02:16:56 PDT 2020
Author: Florian Hahn
Date: 2020-09-03T10:06:51+01:00
New Revision: ce654f4be085f0039e7c0d2f1e37db25931e56e2
URL: https://github.com/llvm/llvm-project/commit/ce654f4be085f0039e7c0d2f1e37db25931e56e2
DIFF: https://github.com/llvm/llvm-project/commit/ce654f4be085f0039e7c0d2f1e37db25931e56e2.diff
LOG: [SCCP] Add test where dereferenceable ptr is replaced with un-dereferenceable one
Added:
llvm/test/Transforms/SCCP/replace-dereferenceable-ptr-with-undereferenceable.ll
Modified:
Removed:
################################################################################
diff --git a/llvm/test/Transforms/SCCP/replace-dereferenceable-ptr-with-undereferenceable.ll b/llvm/test/Transforms/SCCP/replace-dereferenceable-ptr-with-undereferenceable.ll
new file mode 100644
index 000000000000..5857ce2d30b7
--- /dev/null
+++ b/llvm/test/Transforms/SCCP/replace-dereferenceable-ptr-with-undereferenceable.ll
@@ -0,0 +1,86 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt -ipsccp -S %s | FileCheck %s
+
+ at y = common global [1 x i32] zeroinitializer, align 4
+ at x = common global [1 x i32] zeroinitializer, align 4
+
+define i32 @eq_undereferenceable(i32* %p) {
+; CHECK-LABEL: @eq_undereferenceable(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: store i32 1, i32* getelementptr inbounds ([1 x i32], [1 x i32]* @y, i64 0, i64 0), align 4
+; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32* [[P:%.*]], getelementptr inbounds (i32, i32* getelementptr inbounds ([1 x i32], [1 x i32]* @x, i64 0, i64 0), i64 1)
+; CHECK-NEXT: br i1 [[CMP]], label [[IF_THEN:%.*]], label [[IF_END:%.*]]
+; CHECK: if.then:
+; CHECK-NEXT: store i32 2, i32* getelementptr inbounds (i32, i32* getelementptr inbounds ([1 x i32], [1 x i32]* @x, i64 0, i64 0), i64 1), align 4
+; CHECK-NEXT: br label [[IF_END]]
+; CHECK: if.end:
+; CHECK-NEXT: [[TMP0:%.*]] = load i32, i32* getelementptr inbounds ([1 x i32], [1 x i32]* @y, i64 0, i64 0), align 4
+; CHECK-NEXT: ret i32 [[TMP0]]
+;
+entry:
+ store i32 1, i32* getelementptr inbounds ([1 x i32], [1 x i32]* @y, i64 0, i64 0), align 4
+ %cmp = icmp eq i32* %p, getelementptr inbounds (i32, i32* getelementptr inbounds ([1 x i32], [1 x i32]* @x, i64 0, i64 0), i64 1)
+ br i1 %cmp, label %if.then, label %if.end
+
+if.then: ; preds = %entry
+ store i32 2, i32* %p, align 4
+ br label %if.end
+
+if.end: ; preds = %if.then, %entry
+ %0 = load i32, i32* getelementptr inbounds ([1 x i32], [1 x i32]* @y, i64 0, i64 0), align 4
+ ret i32 %0
+}
+
+
+define i32 @eq_dereferenceable(i32* %p) {
+; CHECK-LABEL: @eq_dereferenceable(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: store i32 1, i32* getelementptr inbounds ([1 x i32], [1 x i32]* @y, i64 0, i64 0), align 4
+; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32* [[P:%.*]], getelementptr inbounds ([1 x i32], [1 x i32]* @x, i64 0, i64 0)
+; CHECK-NEXT: br i1 [[CMP]], label [[IF_THEN:%.*]], label [[IF_END:%.*]]
+; CHECK: if.then:
+; CHECK-NEXT: store i32 2, i32* getelementptr inbounds ([1 x i32], [1 x i32]* @x, i64 0, i64 0), align 4
+; CHECK-NEXT: br label [[IF_END]]
+; CHECK: if.end:
+; CHECK-NEXT: [[TMP0:%.*]] = load i32, i32* getelementptr inbounds ([1 x i32], [1 x i32]* @y, i64 0, i64 0), align 4
+; CHECK-NEXT: ret i32 [[TMP0]]
+;
+entry:
+ store i32 1, i32* getelementptr inbounds ([1 x i32], [1 x i32]* @y, i64 0, i64 0), align 4
+ %cmp = icmp eq i32* %p, getelementptr inbounds (i32, i32* getelementptr inbounds ([1 x i32], [1 x i32]* @x, i64 0, i64 0), i64 0)
+ br i1 %cmp, label %if.then, label %if.end
+
+if.then: ; preds = %entry
+ store i32 2, i32* %p, align 4
+ br label %if.end
+
+if.end: ; preds = %if.then, %entry
+ %0 = load i32, i32* getelementptr inbounds ([1 x i32], [1 x i32]* @y, i64 0, i64 0), align 4
+ ret i32 %0
+}
+
+define i1 @eq_undereferenceable_cmp_simp(i32* %p) {
+; CHECK-LABEL: @eq_undereferenceable_cmp_simp(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: [[CMP_0:%.*]] = icmp eq i32* [[P:%.*]], getelementptr inbounds (i32, i32* getelementptr inbounds ([1 x i32], [1 x i32]* @x, i64 0, i64 0), i64 1)
+; CHECK-NEXT: br i1 [[CMP_0]], label [[IF_THEN:%.*]], label [[IF_END:%.*]]
+; CHECK: if.then:
+; CHECK-NEXT: store i32 2, i32* getelementptr inbounds (i32, i32* getelementptr inbounds ([1 x i32], [1 x i32]* @x, i64 0, i64 0), i64 1), align 4
+; CHECK-NEXT: ret i1 true
+; CHECK: if.end:
+; CHECK-NEXT: [[CMP_2:%.*]] = icmp eq i32* [[P]], getelementptr inbounds (i32, i32* getelementptr inbounds ([1 x i32], [1 x i32]* @x, i64 0, i64 0), i64 1)
+; CHECK-NEXT: ret i1 [[CMP_2]]
+;
+entry:
+ %cmp.0 = icmp eq i32* %p, getelementptr inbounds (i32, i32* getelementptr inbounds ([1 x i32], [1 x i32]* @x, i64 0, i64 0), i64 1)
+ br i1 %cmp.0, label %if.then, label %if.end
+
+if.then: ; preds = %entry
+ store i32 2, i32* %p, align 4
+ %cmp.1 = icmp eq i32* %p, getelementptr inbounds (i32, i32* getelementptr inbounds ([1 x i32], [1 x i32]* @x, i64 0, i64 0), i64 1)
+ ret i1 %cmp.1
+
+if.end: ; preds = %if.then, %entry
+ %cmp.2 = icmp eq i32* %p, getelementptr inbounds (i32, i32* getelementptr inbounds ([1 x i32], [1 x i32]* @x, i64 0, i64 0), i64 1)
+ ret i1 %cmp.2
+}
More information about the llvm-commits
mailing list