[llvm] f3dd3a6 - [Attributor] AAUndefinedBehavior: Use AAValueSimplify in memory accessing instructions.
Stefanos Baziotis via llvm-commits
llvm-commits at lists.llvm.org
Sat Apr 4 16:48:28 PDT 2020
Author: Stefanos Baziotis
Date: 2020-04-05T02:46:26+03:00
New Revision: f3dd3a66d3d5643a5e6f46bb18dee3be3a5898cd
URL: https://github.com/llvm/llvm-project/commit/f3dd3a66d3d5643a5e6f46bb18dee3be3a5898cd
DIFF: https://github.com/llvm/llvm-project/commit/f3dd3a66d3d5643a5e6f46bb18dee3be3a5898cd.diff
LOG: [Attributor] AAUndefinedBehavior: Use AAValueSimplify in memory accessing instructions.
Query AAValueSimplify on pointers in memory accessing instructions to take
advantage of the constant propagation (or any other value simplification) of such values.
Added:
Modified:
llvm/lib/Transforms/IPO/Attributor.cpp
llvm/test/Transforms/Attributor/ArgumentPromotion/2008-07-02-array-indexing.ll
llvm/test/Transforms/Attributor/ArgumentPromotion/X86/attributes.ll
llvm/test/Transforms/Attributor/ArgumentPromotion/X86/min-legal-vector-width.ll
llvm/test/Transforms/Attributor/ArgumentPromotion/alignment.ll
llvm/test/Transforms/Attributor/ArgumentPromotion/control-flow.ll
llvm/test/Transforms/Attributor/ArgumentPromotion/fp80.ll
llvm/test/Transforms/Attributor/ArgumentPromotion/profile.ll
llvm/test/Transforms/Attributor/ArgumentPromotion/reserve-tbaa.ll
llvm/test/Transforms/Attributor/ArgumentPromotion/sret.ll
llvm/test/Transforms/Attributor/IPConstantProp/2009-09-24-byval-ptr.ll
llvm/test/Transforms/Attributor/IPConstantProp/PR26044.ll
llvm/test/Transforms/Attributor/IPConstantProp/openmp_parallel_for.ll
llvm/test/Transforms/Attributor/internal-noalias.ll
llvm/test/Transforms/Attributor/returned.ll
llvm/test/Transforms/Attributor/undefined_behavior.ll
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/IPO/Attributor.cpp b/llvm/lib/Transforms/IPO/Attributor.cpp
index fe8ce92e66c5..483cb710c4e8 100644
--- a/llvm/lib/Transforms/IPO/Attributor.cpp
+++ b/llvm/lib/Transforms/IPO/Attributor.cpp
@@ -2355,14 +2355,21 @@ struct AAUndefinedBehaviorImpl : public AAUndefinedBehavior {
assert(PtrOp &&
"Expected pointer operand of memory accessing instruction");
+ // Either we stopped and the appropriate action was taken,
+ // or we got back a simplified value to continue.
+ Optional<Value *> SimplifiedPtrOp = stopOnUndefOrAssumed(A, PtrOp, &I);
+ if (!SimplifiedPtrOp.hasValue())
+ return true;
+ const Value *PtrOpVal = SimplifiedPtrOp.getValue();
+
// A memory access through a pointer is considered UB
// only if the pointer has constant null value.
// TODO: Expand it to not only check constant values.
- if (!isa<ConstantPointerNull>(PtrOp)) {
+ if (!isa<ConstantPointerNull>(PtrOpVal)) {
AssumedNoUBInsts.insert(&I);
return true;
}
- const Type *PtrTy = PtrOp->getType();
+ const Type *PtrTy = PtrOpVal->getType();
// Because we only consider instructions inside functions,
// assume that a parent function exists.
diff --git a/llvm/test/Transforms/Attributor/ArgumentPromotion/2008-07-02-array-indexing.ll b/llvm/test/Transforms/Attributor/ArgumentPromotion/2008-07-02-array-indexing.ll
index 65d1528151b9..9a4956be40a5 100644
--- a/llvm/test/Transforms/Attributor/ArgumentPromotion/2008-07-02-array-indexing.ll
+++ b/llvm/test/Transforms/Attributor/ArgumentPromotion/2008-07-02-array-indexing.ll
@@ -1,19 +1,20 @@
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --function-signature --scrub-attributes
-; RUN: opt -passes=attributor -aa-pipeline='basic-aa' -attributor-disable=false -attributor-max-iterations-verify -attributor-max-iterations=2 -S < %s | FileCheck %s
+; RUN: opt -passes=attributor -aa-pipeline='basic-aa' -attributor-disable=false -attributor-max-iterations-verify -attributor-max-iterations=3 -S < %s | FileCheck %s
; PR2498
; This test tries to convince CHECK about promoting the load from %A + 2,
; because there is a load of %A in the entry block
define internal i32 @callee(i1 %C, i32* %A) {
-; CHECK-LABEL: define {{[^@]+}}@callee()
+; CHECK-LABEL: define {{[^@]+}}@callee
+; CHECK-SAME: (i32* nocapture nofree nonnull readonly align 4 dereferenceable(4) [[A:%.*]])
; CHECK-NEXT: entry:
-; CHECK-NEXT: [[A_0:%.*]] = load i32, i32* null, align 536870912
+; CHECK-NEXT: [[A_0:%.*]] = load i32, i32* %A
; CHECK-NEXT: br label [[F:%.*]]
; CHECK: T:
; CHECK-NEXT: unreachable
; CHECK: F:
-; CHECK-NEXT: [[A_2:%.*]] = getelementptr i32, i32* null, i32 2
-; CHECK-NEXT: [[R:%.*]] = load i32, i32* [[A_2]], align 4
+; CHECK-NEXT: [[A_2:%.*]] = getelementptr i32, i32* %A, i32 2
+; CHECK-NEXT: [[R:%.*]] = load i32, i32* [[A_2]]
; CHECK-NEXT: ret i32 [[R]]
;
entry:
@@ -31,12 +32,12 @@ F:
ret i32 %R
}
-define i32 @foo() {
-; CHECK-LABEL: define {{[^@]+}}@foo()
-; CHECK-NEXT: [[X:%.*]] = call i32 @callee()
+define i32 @foo(i32* %A) {
+; CHECK-LABEL: define {{[^@]+}}@foo(
+; CHECK-NEXT: [[X:%.*]] = call i32 @callee(i32* nocapture nofree readonly align 4 %A)
; CHECK-NEXT: ret i32 [[X]]
;
- %X = call i32 @callee(i1 false, i32* null) ; <i32> [#uses=1]
+ %X = call i32 @callee(i1 false, i32* %A) ; <i32> [#uses=1]
ret i32 %X
}
diff --git a/llvm/test/Transforms/Attributor/ArgumentPromotion/X86/attributes.ll b/llvm/test/Transforms/Attributor/ArgumentPromotion/X86/attributes.ll
index 9f1677976015..08e254f382ec 100644
--- a/llvm/test/Transforms/Attributor/ArgumentPromotion/X86/attributes.ll
+++ b/llvm/test/Transforms/Attributor/ArgumentPromotion/X86/attributes.ll
@@ -1,5 +1,5 @@
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --function-signature --scrub-attributes
-; RUN: opt -S -passes='attributor' -aa-pipeline='basic-aa' -attributor-disable=false -attributor-max-iterations-verify -attributor-max-iterations=2 < %s | FileCheck %s
+; RUN: opt -S -passes='attributor' -aa-pipeline='basic-aa' -attributor-disable=false -attributor-max-iterations-verify -attributor-max-iterations=3 < %s | FileCheck %s
; Test that we only promote arguments when the caller/callee have compatible
; function attrubtes.
diff --git a/llvm/test/Transforms/Attributor/ArgumentPromotion/X86/min-legal-vector-width.ll b/llvm/test/Transforms/Attributor/ArgumentPromotion/X86/min-legal-vector-width.ll
index bbaf3d6496a9..b994aba78dc8 100644
--- a/llvm/test/Transforms/Attributor/ArgumentPromotion/X86/min-legal-vector-width.ll
+++ b/llvm/test/Transforms/Attributor/ArgumentPromotion/X86/min-legal-vector-width.ll
@@ -1,5 +1,5 @@
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --function-signature --scrub-attributes
-; RUN: opt -S -passes='attributor' -aa-pipeline='basic-aa' -attributor-disable=false -attributor-max-iterations-verify -attributor-max-iterations=2 < %s | FileCheck %s
+; RUN: opt -S -passes='attributor' -aa-pipeline='basic-aa' -attributor-disable=false -attributor-max-iterations-verify -attributor-max-iterations=3 < %s | FileCheck %s
; Test that we only promote arguments when the caller/callee have compatible
; function attrubtes.
diff --git a/llvm/test/Transforms/Attributor/ArgumentPromotion/alignment.ll b/llvm/test/Transforms/Attributor/ArgumentPromotion/alignment.ll
index ace6b60e99a7..3b0085a019e4 100644
--- a/llvm/test/Transforms/Attributor/ArgumentPromotion/alignment.ll
+++ b/llvm/test/Transforms/Attributor/ArgumentPromotion/alignment.ll
@@ -1,5 +1,5 @@
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --function-signature --scrub-attributes
-; RUN: opt -S -passes='attributor' -aa-pipeline='basic-aa' -attributor-disable=false -attributor-max-iterations-verify -attributor-max-iterations=2 < %s | FileCheck %s
+; RUN: opt -S -passes='attributor' -aa-pipeline='basic-aa' -attributor-disable=false -attributor-max-iterations-verify -attributor-max-iterations=3 < %s | FileCheck %s
define void @f() {
; CHECK-LABEL: define {{[^@]+}}@f()
diff --git a/llvm/test/Transforms/Attributor/ArgumentPromotion/control-flow.ll b/llvm/test/Transforms/Attributor/ArgumentPromotion/control-flow.ll
index 944a12a60d1a..494107d17d8b 100644
--- a/llvm/test/Transforms/Attributor/ArgumentPromotion/control-flow.ll
+++ b/llvm/test/Transforms/Attributor/ArgumentPromotion/control-flow.ll
@@ -1,5 +1,5 @@
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --function-signature --scrub-attributes
-; RUN: opt -S -passes='attributor' -aa-pipeline='basic-aa' -attributor-disable=false -attributor-max-iterations-verify -attributor-max-iterations=2 < %s | FileCheck %s
+; RUN: opt -S -passes='attributor' -aa-pipeline='basic-aa' -attributor-disable=false -attributor-max-iterations-verify -attributor-max-iterations=3 < %s | FileCheck %s
; Don't promote around control flow.
define internal i32 @callee(i1 %C, i32* %P) {
diff --git a/llvm/test/Transforms/Attributor/ArgumentPromotion/fp80.ll b/llvm/test/Transforms/Attributor/ArgumentPromotion/fp80.ll
index 28850c37c3da..b9ee30fac9b9 100644
--- a/llvm/test/Transforms/Attributor/ArgumentPromotion/fp80.ll
+++ b/llvm/test/Transforms/Attributor/ArgumentPromotion/fp80.ll
@@ -1,5 +1,5 @@
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --function-signature --scrub-attributes
-; RUN: opt -S -passes=attributor -aa-pipeline='basic-aa' -attributor-disable=false -attributor-max-iterations-verify -attributor-max-iterations=2 < %s | FileCheck %s
+; RUN: opt -S -passes=attributor -aa-pipeline='basic-aa' -attributor-disable=false -attributor-max-iterations-verify -attributor-max-iterations=3 < %s | FileCheck %s
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"
diff --git a/llvm/test/Transforms/Attributor/ArgumentPromotion/profile.ll b/llvm/test/Transforms/Attributor/ArgumentPromotion/profile.ll
index 1bf7ed6d2fe5..b9b10cf86005 100644
--- a/llvm/test/Transforms/Attributor/ArgumentPromotion/profile.ll
+++ b/llvm/test/Transforms/Attributor/ArgumentPromotion/profile.ll
@@ -1,5 +1,5 @@
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --function-signature --scrub-attributes
-; RUN: opt -S -passes='attributor' -aa-pipeline='basic-aa' -attributor-disable=false -attributor-max-iterations-verify -attributor-max-iterations=2 < %s | FileCheck %s
+; RUN: opt -S -passes='attributor' -aa-pipeline='basic-aa' -attributor-disable=false -attributor-max-iterations-verify -attributor-max-iterations=3 < %s | FileCheck %s
target datalayout = "E-p:64:64:64-a0:0:8-f32:32:32-f64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-v64:64:64-v128:128:128"
; Checks if !prof metadata is corret in deadargelim.
diff --git a/llvm/test/Transforms/Attributor/ArgumentPromotion/reserve-tbaa.ll b/llvm/test/Transforms/Attributor/ArgumentPromotion/reserve-tbaa.ll
index a889177f5933..d8d582b12563 100644
--- a/llvm/test/Transforms/Attributor/ArgumentPromotion/reserve-tbaa.ll
+++ b/llvm/test/Transforms/Attributor/ArgumentPromotion/reserve-tbaa.ll
@@ -1,5 +1,5 @@
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --function-signature --scrub-attributes
-; RUN: opt -S -passes='attributor' -aa-pipeline='basic-aa' -attributor-disable=false -attributor-max-iterations-verify -attributor-max-iterations=2 < %s | FileCheck %s
+; RUN: opt -S -passes='attributor' -aa-pipeline='basic-aa' -attributor-disable=false -attributor-max-iterations-verify -attributor-max-iterations=3 < %s | FileCheck %s
; PR17906
; When we promote two arguments in a single function with
diff erent types,
diff --git a/llvm/test/Transforms/Attributor/ArgumentPromotion/sret.ll b/llvm/test/Transforms/Attributor/ArgumentPromotion/sret.ll
index e0cb81fbcbf3..5e3e9881c509 100644
--- a/llvm/test/Transforms/Attributor/ArgumentPromotion/sret.ll
+++ b/llvm/test/Transforms/Attributor/ArgumentPromotion/sret.ll
@@ -1,5 +1,5 @@
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --function-signature --scrub-attributes
-; RUN: opt -S -passes='attributor' -aa-pipeline='basic-aa' -attributor-disable=false -attributor-max-iterations-verify -attributor-max-iterations=2 < %s | FileCheck %s
+; RUN: opt -S -passes='attributor' -aa-pipeline='basic-aa' -attributor-disable=false -attributor-max-iterations-verify -attributor-max-iterations=4 < %s | FileCheck %s
target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-pc-windows-msvc"
diff --git a/llvm/test/Transforms/Attributor/IPConstantProp/2009-09-24-byval-ptr.ll b/llvm/test/Transforms/Attributor/IPConstantProp/2009-09-24-byval-ptr.ll
index eccfcb7e7d2a..26b37d7a67eb 100644
--- a/llvm/test/Transforms/Attributor/IPConstantProp/2009-09-24-byval-ptr.ll
+++ b/llvm/test/Transforms/Attributor/IPConstantProp/2009-09-24-byval-ptr.ll
@@ -1,5 +1,5 @@
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --function-signature --scrub-attributes
-; RUN: opt -S -passes=attributor -aa-pipeline='basic-aa' -attributor-disable=false -attributor-max-iterations-verify -attributor-max-iterations=5 < %s | FileCheck %s
+; RUN: opt -S -passes=attributor -aa-pipeline='basic-aa' -attributor-disable=false -attributor-max-iterations-verify -attributor-max-iterations=6 < %s | FileCheck %s
; Don't constant-propagate byval pointers, since they are not pointers!
; PR5038
%struct.MYstr = type { i8, i32 }
diff --git a/llvm/test/Transforms/Attributor/IPConstantProp/PR26044.ll b/llvm/test/Transforms/Attributor/IPConstantProp/PR26044.ll
index b7f24b8854a0..cf77bbf78436 100644
--- a/llvm/test/Transforms/Attributor/IPConstantProp/PR26044.ll
+++ b/llvm/test/Transforms/Attributor/IPConstantProp/PR26044.ll
@@ -3,31 +3,34 @@
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"
-define void @fn2(i32* %P) {
+define void @fn2(i32* %P, i1 %C) {
; CHECK-LABEL: define {{[^@]+}}@fn2
-; CHECK-SAME: (i32* nocapture nofree writeonly [[P:%.*]])
+; CHECK-SAME: (i32* nocapture nofree [[P:%.*]], i1 %C)
; CHECK-NEXT: entry:
; CHECK-NEXT: br label [[IF_END:%.*]]
; CHECK: for.cond1:
-; CHECK-NEXT: unreachable
+; CHECK-NEXT: br i1 %C, label %if.end, label %exit
; CHECK: if.end:
-; CHECK-NEXT: [[TMP0:%.*]] = load i32, i32* undef, align 4
+; CHECK-NEXT: [[E_2:%.*]] = phi i32* [ %P, %entry ], [ null, %for.cond1 ]
+; CHECK-NEXT: [[TMP0:%.*]] = load i32, i32* [[E_2]], align 4
; CHECK-NEXT: [[CALL:%.*]] = call i32 @fn1(i32 [[TMP0]])
; CHECK-NEXT: store i32 [[CALL]], i32* [[P]]
-; CHECK-NEXT: br label [[FOR_COND1:%.*]]
+; CHECK-NEXT: br label %for.cond1
;
entry:
br label %if.end
-for.cond1: ; preds = %if.end, %for.end
- br i1 undef, label %if.end, label %if.end
+for.cond1: ; preds = %if.end
+ br i1 %C, label %if.end, label %exit
-if.end: ; preds = %lbl, %for.cond1
- %e.2 = phi i32* [ undef, %entry ], [ null, %for.cond1 ], [ null, %for.cond1 ]
+if.end: ; preds = %entry, %for.cond1
+ %e.2 = phi i32* [ %P, %entry ], [ null, %for.cond1 ]
%0 = load i32, i32* %e.2, align 4
%call = call i32 @fn1(i32 %0)
store i32 %call, i32* %P
br label %for.cond1
+exit:
+ ret void
}
define internal i32 @fn1(i32 %p1) {
@@ -44,31 +47,34 @@ entry:
ret i32 %cond
}
-define void @fn_no_null_opt(i32* %P) #0 {
+define void @fn_no_null_opt(i32* %P, i1 %C) "null-pointer-is-valid"="true" {
; CHECK-LABEL: define {{[^@]+}}@fn_no_null_opt
-; CHECK-SAME: (i32* nocapture nofree writeonly [[P:%.*]])
+; CHECK-SAME: (i32* nocapture nofree writeonly [[P:%.*]], i1 %C)
; CHECK-NEXT: entry:
; CHECK-NEXT: br label [[IF_END:%.*]]
; CHECK: for.cond1:
-; CHECK-NEXT: unreachable
+; CHECK-NEXT: br i1 %C, label %if.end, label %exit
; CHECK: if.end:
-; CHECK-NEXT: [[TMP0:%.*]] = load i32, i32* undef, align 4
+; CHECK-NEXT: [[E_2:%.*]] = phi i32* [ undef, %entry ], [ null, %for.cond1 ]
+; CHECK-NEXT: [[TMP0:%.*]] = load i32, i32* null, align 4
; CHECK-NEXT: [[CALL:%.*]] = call i32 @fn0(i32 [[TMP0]])
; CHECK-NEXT: store i32 [[CALL]], i32* [[P]]
-; CHECK-NEXT: br label [[FOR_COND1:%.*]]
+; CHECK-NEXT: br label %for.cond1
;
entry:
br label %if.end
-for.cond1: ; preds = %if.end, %for.end
- br i1 undef, label %if.end, label %if.end
+for.cond1: ; preds = %if.end
+ br i1 %C, label %if.end, label %exit
-if.end: ; preds = %lbl, %for.cond1
- %e.2 = phi i32* [ undef, %entry ], [ null, %for.cond1 ], [ null, %for.cond1 ]
+if.end: ; preds = %entry, %for.cond1
+ %e.2 = phi i32* [ undef, %entry ], [ null, %for.cond1 ]
%0 = load i32, i32* %e.2, align 4
%call = call i32 @fn0(i32 %0)
store i32 %call, i32* %P
br label %for.cond1
+exit:
+ ret void
}
define internal i32 @fn0(i32 %p1) {
@@ -84,5 +90,3 @@ entry:
%cond = select i1 %tobool, i32 %p1, i32 %p1
ret i32 %cond
}
-
-attributes #0 = { "null-pointer-is-valid"="true" }
diff --git a/llvm/test/Transforms/Attributor/IPConstantProp/openmp_parallel_for.ll b/llvm/test/Transforms/Attributor/IPConstantProp/openmp_parallel_for.ll
index c919bdbec49b..1e662f1f199f 100644
--- a/llvm/test/Transforms/Attributor/IPConstantProp/openmp_parallel_for.ll
+++ b/llvm/test/Transforms/Attributor/IPConstantProp/openmp_parallel_for.ll
@@ -1,5 +1,5 @@
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --function-signature --scrub-attributes
-; RUN: opt -S -passes=attributor -aa-pipeline='basic-aa' -attributor-disable=false -attributor-max-iterations-verify -attributor-max-iterations=2 < %s | FileCheck %s
+; RUN: opt -S -passes=attributor -aa-pipeline='basic-aa' -attributor-disable=false -attributor-max-iterations-verify -attributor-max-iterations=3 < %s | FileCheck %s
;
; void bar(int, float, double);
;
diff --git a/llvm/test/Transforms/Attributor/internal-noalias.ll b/llvm/test/Transforms/Attributor/internal-noalias.ll
index f04478ceb738..600da85001bd 100644
--- a/llvm/test/Transforms/Attributor/internal-noalias.ll
+++ b/llvm/test/Transforms/Attributor/internal-noalias.ll
@@ -1,4 +1,4 @@
-; RUN: opt -S -passes=attributor -aa-pipeline='basic-aa' -attributor-disable=false -attributor-max-iterations-verify -attributor-annotate-decl-cs -attributor-max-iterations=6 < %s | FileCheck %s
+; RUN: opt -S -passes=attributor -aa-pipeline='basic-aa' -attributor-disable=false -attributor-max-iterations-verify -attributor-annotate-decl-cs -attributor-max-iterations=7 < %s | FileCheck %s
define dso_local i32 @visible(i32* noalias %A, i32* noalias %B) #0 {
entry:
diff --git a/llvm/test/Transforms/Attributor/returned.ll b/llvm/test/Transforms/Attributor/returned.ll
index e8b031b1cf61..98399fe2f9cc 100644
--- a/llvm/test/Transforms/Attributor/returned.ll
+++ b/llvm/test/Transforms/Attributor/returned.ll
@@ -1,4 +1,4 @@
-; RUN: opt -attributor -attributor-manifest-internal -attributor-disable=false -attributor-max-iterations-verify -attributor-annotate-decl-cs -attributor-max-iterations=5 -S < %s | FileCheck %s --check-prefix=ATTRIBUTOR
+; RUN: opt -attributor -attributor-manifest-internal -attributor-disable=false -attributor-max-iterations-verify -attributor-annotate-decl-cs -attributor-max-iterations=6 -S < %s | FileCheck %s --check-prefix=ATTRIBUTOR
; RUN: opt -attributor -attributor-manifest-internal -attributor-disable=false -attributor-annotate-decl-cs -functionattrs -S < %s | FileCheck %s --check-prefix=BOTH
;
; Copied from Transforms/FunctoinAttrs/read_write_returned_arguments_scc.ll
diff --git a/llvm/test/Transforms/Attributor/undefined_behavior.ll b/llvm/test/Transforms/Attributor/undefined_behavior.ll
index 492dcd1b6293..4265de525e73 100644
--- a/llvm/test/Transforms/Attributor/undefined_behavior.ll
+++ b/llvm/test/Transforms/Attributor/undefined_behavior.ll
@@ -42,6 +42,8 @@ e:
ret void
}
+; Note that while the load is removed (because it's unused), the block
+; is not changed to unreachable
define void @load_null_pointer_is_defined() "null-pointer-is-valid"="true" {
; ATTRIBUTOR-LABEL: @load_null_pointer_is_defined(
; ATTRIBUTOR-NEXT: ret void
@@ -54,16 +56,13 @@ define internal i32* @ret_null() {
ret i32* null
}
-; FIXME: null is propagated but the instruction
-; is not changed to unreachable.
-define i32 @load_null_propagated() {
+define void @load_null_propagated() {
; ATTRIBUTOR-LABEL: @load_null_propagated(
-; ATTRIBUTOR-NEXT: [[A:%.*]] = load i32, i32* null
-; ATTRIBUTOR-NEXT: ret i32 [[A]]
+; ATTRIBUTOR-NEXT: unreachable
;
%ptr = call i32* @ret_null()
%a = load i32, i32* %ptr
- ret i32 %a
+ ret void
}
; -- Store tests --
@@ -101,6 +100,15 @@ define void @store_null_pointer_is_defined() "null-pointer-is-valid"="true" {
ret void
}
+define void @store_null_propagated() {
+; ATTRIBUTOR-LABEL: @store_null_propagated(
+; ATTRIBUTOR-NEXT: unreachable
+;
+ %ptr = call i32* @ret_null()
+ store i32 5, i32* %ptr
+ ret void
+}
+
; -- AtomicRMW tests --
define void @atomicrmw_wholly_unreachable() {
@@ -136,6 +144,15 @@ define void @atomicrmw_null_pointer_is_defined() "null-pointer-is-valid"="true"
ret void
}
+define void @atomicrmw_null_propagated() {
+; ATTRIBUTOR-LABEL: @atomicrmw_null_propagated(
+; ATTRIBUTOR-NEXT: unreachable
+;
+ %ptr = call i32* @ret_null()
+ %a = atomicrmw add i32* %ptr, i32 1 acquire
+ ret void
+}
+
; -- AtomicCmpXchg tests --
define void @atomiccmpxchg_wholly_unreachable() {
@@ -171,6 +188,17 @@ define void @atomiccmpxchg_null_pointer_is_defined() "null-pointer-is-valid"="tr
ret void
}
+define void @atomiccmpxchg_null_propagated() {
+; ATTRIBUTOR-LABEL: @atomiccmpxchg_null_propagated(
+; ATTRIBUTOR-NEXT: unreachable
+;
+ %ptr = call i32* @ret_null()
+ %a = cmpxchg i32* %ptr, i32 2, i32 3 acq_rel monotonic
+ ret void
+}
+
+; -- Conditional branching tests --
+
; Note: The unreachable on %t and %e is _not_ from AAUndefinedBehavior
define i32 @cond_br_on_undef() {
More information about the llvm-commits
mailing list