Commit 2baf000e authored by Johannes Doerfert's avatar Johannes Doerfert
Browse files

[Attributor] `byval` arguments are always `noalias`

`byval` introduces a local copy of the argument. That copy cannot alias
anything.
parent 30ae859c
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -2386,6 +2386,14 @@ struct AANoAliasArgument final
  using Base = AAArgumentFromCallSiteArguments<AANoAlias, AANoAliasImpl>;
  AANoAliasArgument(const IRPosition &IRP) : Base(IRP) {}

  /// See AbstractAttribute::initialize(...).
  void initialize(Attributor &A) override {
    Base::initialize(A);
    // See callsite argument attribute and callee argument attribute.
    if (hasAttr({Attribute::ByVal}))
      indicateOptimisticFixpoint();
  }

  /// See AbstractAttribute::update(...).
  ChangeStatus updateImpl(Attributor &A) override {
    // We have to make sure no-alias on the argument does not break
+1 −1
Original line number Diff line number Diff line
@@ -6,7 +6,7 @@
; Don't drop 'byval' on %X here.
define internal void @f(%struct.ss* byval %b, i32* byval %X, i32 %i) nounwind {
; CHECK-LABEL: define {{[^@]+}}@f
; CHECK-SAME: (%struct.ss* noalias nocapture nofree nonnull byval align 8 dereferenceable(12) [[B:%.*]], i32* nocapture nofree nonnull writeonly byval dereferenceable(4) [[X:%.*]], i32 [[I:%.*]])
; CHECK-SAME: (%struct.ss* noalias nocapture nofree nonnull byval align 8 dereferenceable(12) [[B:%.*]], i32* noalias nocapture nofree nonnull writeonly byval dereferenceable(4) [[X:%.*]], i32 [[I:%.*]])
; CHECK-NEXT:  entry:
; CHECK-NEXT:    [[TMP:%.*]] = getelementptr [[STRUCT_SS:%.*]], %struct.ss* [[B]], i32 0, i32 0
; CHECK-NEXT:    [[TMP1:%.*]] = load i32, i32* [[TMP]], align 8
+1 −1
Original line number Diff line number Diff line
@@ -5,7 +5,7 @@

define internal void @f(%struct.ss* byval  %b, i32* byval %X) nounwind  {
; CHECK-LABEL: define {{[^@]+}}@f
; CHECK-SAME: (%struct.ss* noalias nocapture nofree nonnull byval align 8 dereferenceable(12) [[B:%.*]], i32* nocapture nofree nonnull writeonly byval dereferenceable(4) [[X:%.*]])
; CHECK-SAME: (%struct.ss* noalias nocapture nofree nonnull byval align 8 dereferenceable(12) [[B:%.*]], i32* noalias nocapture nofree nonnull writeonly byval dereferenceable(4) [[X:%.*]])
; CHECK-NEXT:  entry:
; CHECK-NEXT:    [[TMP:%.*]] = getelementptr [[STRUCT_SS:%.*]], %struct.ss* [[B]], i32 0, i32 0
; CHECK-NEXT:    [[TMP1:%.*]] = load i32, i32* [[TMP]], align 8
+1 −1
Original line number Diff line number Diff line
@@ -48,7 +48,7 @@ define internal i64 @AccessPaddingOfStruct(%struct.Foo* byval %a) {

define internal i64 @CaptureAStruct(%struct.Foo* byval %a) {
; CHECK-LABEL: define {{[^@]+}}@CaptureAStruct
; CHECK-SAME: (%struct.Foo* nofree nonnull byval align 8 dereferenceable(16) [[A:%.*]])
; CHECK-SAME: (%struct.Foo* noalias nofree nonnull byval align 8 dereferenceable(16) [[A:%.*]])
; CHECK-NEXT:  entry:
; CHECK-NEXT:    [[A_PTR:%.*]] = alloca %struct.Foo*
; CHECK-NEXT:    br label [[LOOP:%.*]]
+3 −3
Original line number Diff line number Diff line
@@ -10,7 +10,7 @@ declare i8* @foo(%pair*)

define internal void @bar(%pair* byval %Data) {
; CHECK-LABEL: define {{[^@]+}}@bar
; CHECK-SAME: (%pair* byval [[DATA:%.*]])
; CHECK-SAME: (%pair* noalias byval [[DATA:%.*]])
; CHECK-NEXT:    [[TMP1:%.*]] = tail call i8* @foo(%pair* [[DATA]])
; CHECK-NEXT:    ret void
;
@@ -20,8 +20,8 @@ define internal void @bar(%pair* byval %Data) {

define void @zed(%pair* byval %Data) {
; CHECK-LABEL: define {{[^@]+}}@zed
; CHECK-SAME: (%pair* nocapture readonly byval [[DATA:%.*]])
; CHECK-NEXT:    call void @bar(%pair* nocapture readonly byval [[DATA]])
; CHECK-SAME: (%pair* noalias nocapture readonly byval [[DATA:%.*]])
; CHECK-NEXT:    call void @bar(%pair* noalias nocapture readonly byval [[DATA]])
; CHECK-NEXT:    ret void
;
  call void @bar(%pair* byval %Data)
Loading