Index: llvm/lib/Transforms/IPO/Attributor.cpp =================================================================== --- llvm/lib/Transforms/IPO/Attributor.cpp +++ llvm/lib/Transforms/IPO/Attributor.cpp @@ -2355,14 +2355,21 @@ 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 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(PtrOp)) { + if (!isa(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. Index: llvm/test/Transforms/Attributor/ArgumentPromotion/2008-07-02-array-indexing.ll =================================================================== --- llvm/test/Transforms/Attributor/ArgumentPromotion/2008-07-02-array-indexing.ll +++ 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 @@ 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) ; [#uses=1] + %X = call i32 @callee(i1 false, i32* %A) ; [#uses=1] ret i32 %X } Index: llvm/test/Transforms/Attributor/ArgumentPromotion/X86/attributes.ll =================================================================== --- llvm/test/Transforms/Attributor/ArgumentPromotion/X86/attributes.ll +++ 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. Index: llvm/test/Transforms/Attributor/ArgumentPromotion/X86/min-legal-vector-width.ll =================================================================== --- llvm/test/Transforms/Attributor/ArgumentPromotion/X86/min-legal-vector-width.ll +++ 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. Index: llvm/test/Transforms/Attributor/ArgumentPromotion/alignment.ll =================================================================== --- llvm/test/Transforms/Attributor/ArgumentPromotion/alignment.ll +++ 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() Index: llvm/test/Transforms/Attributor/ArgumentPromotion/control-flow.ll =================================================================== --- llvm/test/Transforms/Attributor/ArgumentPromotion/control-flow.ll +++ 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) { Index: llvm/test/Transforms/Attributor/ArgumentPromotion/fp80.ll =================================================================== --- llvm/test/Transforms/Attributor/ArgumentPromotion/fp80.ll +++ 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" Index: llvm/test/Transforms/Attributor/ArgumentPromotion/profile.ll =================================================================== --- llvm/test/Transforms/Attributor/ArgumentPromotion/profile.ll +++ 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. Index: llvm/test/Transforms/Attributor/ArgumentPromotion/reserve-tbaa.ll =================================================================== --- llvm/test/Transforms/Attributor/ArgumentPromotion/reserve-tbaa.ll +++ 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 different types, Index: llvm/test/Transforms/Attributor/ArgumentPromotion/sret.ll =================================================================== --- llvm/test/Transforms/Attributor/ArgumentPromotion/sret.ll +++ 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" Index: llvm/test/Transforms/Attributor/IPConstantProp/2009-09-24-byval-ptr.ll =================================================================== --- llvm/test/Transforms/Attributor/IPConstantProp/2009-09-24-byval-ptr.ll +++ 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 } Index: llvm/test/Transforms/Attributor/IPConstantProp/PR26044.ll =================================================================== --- llvm/test/Transforms/Attributor/IPConstantProp/PR26044.ll +++ 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 @@ 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 @@ %cond = select i1 %tobool, i32 %p1, i32 %p1 ret i32 %cond } - -attributes #0 = { "null-pointer-is-valid"="true" } Index: llvm/test/Transforms/Attributor/IPConstantProp/openmp_parallel_for.ll =================================================================== --- llvm/test/Transforms/Attributor/IPConstantProp/openmp_parallel_for.ll +++ 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); ; Index: llvm/test/Transforms/Attributor/internal-noalias.ll =================================================================== --- llvm/test/Transforms/Attributor/internal-noalias.ll +++ 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: Index: llvm/test/Transforms/Attributor/returned.ll =================================================================== --- llvm/test/Transforms/Attributor/returned.ll +++ 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 Index: llvm/test/Transforms/Attributor/undefined_behavior.ll =================================================================== --- llvm/test/Transforms/Attributor/undefined_behavior.ll +++ llvm/test/Transforms/Attributor/undefined_behavior.ll @@ -42,6 +42,8 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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() {