Index: llvm/lib/Transforms/IPO/Attributor.cpp =================================================================== --- llvm/lib/Transforms/IPO/Attributor.cpp +++ llvm/lib/Transforms/IPO/Attributor.cpp @@ -34,9 +34,9 @@ #include "llvm/IR/IRBuilder.h" #include "llvm/IR/InstIterator.h" #include "llvm/IR/IntrinsicInst.h" +#include "llvm/IR/NoFolder.h" #include "llvm/IR/Verifier.h" #include "llvm/InitializePasses.h" -#include "llvm/IR/NoFolder.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/Debug.h" #include "llvm/Support/raw_ostream.h" @@ -2187,14 +2187,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. @@ -5293,7 +5300,7 @@ createReplacementValues( PrivatizableType.getValue(), ACS, ACS.getCallArgOperand(ARI.getReplacedArg().getArgNo()), - NewArgOperands); + NewArgOperands); }; // Collect the types that will replace the privatizable type in the function @@ -7552,9 +7559,9 @@ } template -raw_ostream & -llvm::operator<<(raw_ostream &OS, - const IntegerStateBase &S) { +raw_ostream &llvm:: +operator<<(raw_ostream &OS, + const IntegerStateBase &S) { return OS << "(" << S.getKnown() << "-" << S.getAssumed() << ")" << static_cast(S); } Index: llvm/test/Transforms/Attributor/ArgumentPromotion/2008-02-01-ReturnAttrs.ll =================================================================== --- llvm/test/Transforms/Attributor/ArgumentPromotion/2008-02-01-ReturnAttrs.ll +++ llvm/test/Transforms/Attributor/ArgumentPromotion/2008-02-01-ReturnAttrs.ll @@ -1,5 +1,5 @@ ; 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 define internal i32 @deref(i32* %x) nounwind { ; CHECK-LABEL: define {{[^@]+}}@deref 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 @@ -6,14 +6,14 @@ ; because there is a load of %A in the entry block define internal i32 @callee(i1 %C, i32* %A) { ; CHECK-LABEL: define {{[^@]+}}@callee -; CHECK-SAME: (i1 [[C:%.*]], i32* noalias nocapture nofree nonnull readonly align 536870912 dereferenceable(4) [[A:%.*]]) +; CHECK-SAME: (i1 [[C:%.*]], i32* nocapture nofree nonnull readonly 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: [[A_2:%.*]] = getelementptr i32, i32* %A, i32 2 ; CHECK-NEXT: [[R:%.*]] = load i32, i32* [[A_2]] ; CHECK-NEXT: ret i32 [[R]] ; @@ -32,12 +32,11 @@ ret i32 %R } -define i32 @foo() { -; CHECK-LABEL: define {{[^@]+}}@foo() -; CHECK-NEXT: [[X:%.*]] = call i32 @callee(i1 false, i32* noalias nofree readonly align 536870912 null) +define i32 @foo(i32* %A) { +; CHECK-LABEL: define {{[^@]+}}@foo( +; CHECK-NEXT: [[X:%.*]] = call i32 @callee(i1 false, i32* nocapture nofree readonly %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/crash.ll =================================================================== --- llvm/test/Transforms/Attributor/ArgumentPromotion/crash.ll +++ llvm/test/Transforms/Attributor/ArgumentPromotion/crash.ll @@ -1,6 +1,6 @@ ; 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=3 < %s | FileCheck %s --check-prefixes=CHECK,ATTRIBUTOR -; RUN: opt -S -passes='cgscc(inline),attributor' -aa-pipeline='basic-aa' -attributor-disable=false -attributor-max-iterations-verify -attributor-max-iterations=3 < %s | FileCheck %s --check-prefixes=CHECK,INLINE_ATTRIBUTOR +; RUN: opt -S -passes='attributor' -aa-pipeline='basic-aa' -attributor-disable=false -attributor-max-iterations-verify -attributor-max-iterations=4 < %s | FileCheck %s --check-prefixes=CHECK,ATTRIBUTOR +; RUN: opt -S -passes='cgscc(inline),attributor' -aa-pipeline='basic-aa' -attributor-disable=false -attributor-max-iterations-verify -attributor-max-iterations=4 < %s | FileCheck %s --check-prefixes=CHECK,INLINE_ATTRIBUTOR %S = type { %S* } 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/inalloca.ll =================================================================== --- llvm/test/Transforms/Attributor/ArgumentPromotion/inalloca.ll +++ llvm/test/Transforms/Attributor/ArgumentPromotion/inalloca.ll @@ -1,6 +1,6 @@ ; 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 --check-prefixes=ATTRIBUTOR -; RUN: opt -S -passes='globalopt,attributor' -aa-pipeline='basic-aa' -attributor-disable=false -attributor-max-iterations-verify -attributor-max-iterations=2 < %s | FileCheck %s --check-prefixes=GLOBALOPT_ATTRIBUTOR +; RUN: opt -S -passes='globalopt,attributor' -aa-pipeline='basic-aa' -attributor-disable=false -attributor-max-iterations-verify -attributor-max-iterations=4 < %s | FileCheck %s --check-prefixes=GLOBALOPT_ATTRIBUTOR 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" 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=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 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/align.ll =================================================================== --- llvm/test/Transforms/Attributor/align.ll +++ llvm/test/Transforms/Attributor/align.ll @@ -1,5 +1,5 @@ ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --function-signature --scrub-attributes --turn off -; 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 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" Index: llvm/test/Transforms/Attributor/nocapture-2.ll =================================================================== --- llvm/test/Transforms/Attributor/nocapture-2.ll +++ llvm/test/Transforms/Attributor/nocapture-2.ll @@ -1,4 +1,4 @@ -; RUN: opt -functionattrs -attributor -attributor-manifest-internal -attributor-disable=false -attributor-max-iterations-verify -attributor-annotate-decl-cs -attributor-max-iterations=5 -S < %s | FileCheck %s +; RUN: opt -functionattrs -attributor -attributor-manifest-internal -attributor-disable=false -attributor-max-iterations-verify -attributor-annotate-decl-cs -attributor-max-iterations=6 -S < %s | FileCheck %s ; ; Test cases specifically designed for the "no-capture" argument attribute. ; We use FIXME's to indicate problems and missing attributes. 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