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.
; 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:
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
}
; 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.
; 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.
; 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()
; 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) {
; 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"
; 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.
; 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 different types,
; 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"
; 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 }
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) {
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) {
%cond = select i1 %tobool, i32 %p1, i32 %p1
ret i32 %cond
}
-
-attributes #0 = { "null-pointer-is-valid"="true" }
; 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);
;
-; 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:
-; 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
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
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 --
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() {
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() {
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() {