[PATCH] D93927: [ArgPromotion] Copy !range metadata for loads.

Chenguang Wang via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 26 13:31:02 PDT 2021


wecing added a comment.

Sorry about the inconveniences, @tejohnson. I am fine with rolling this back, but since I do not have write access to the repo, @fhahn, would you like to roll it back?

---

I found a much shorter program that could reproduce this issue:

  %struct.Foo = type { %struct.Bar*, i8 }
  %struct.Bar = type { i32 }
  
  ; Function Attrs: nounwind uwtable
  define i32 @caller(%struct.Foo* dereferenceable(16) %0) local_unnamed_addr #0 {
    %2 = call i32 @func(%struct.Foo* dereferenceable(16) %0)
    ret i32 %2
  }
  
  ; Function Attrs: nounwind uwtable
  define internal i32 @func(%struct.Foo* dereferenceable(16) %0) unnamed_addr #0 {
    %2 = getelementptr inbounds %struct.Foo, %struct.Foo* %0, i64 0, i32 1
    %3 = load i8, i8* %2, align 8
    %4 = icmp eq i8 %3, 0
    br i1 %4, label %10, label %5
  
  5:                                                ; preds = %1
    %6 = getelementptr inbounds %struct.Foo, %struct.Foo* %0, i64 0, i32 0
    %7 = load %struct.Bar*, %struct.Bar** %6, align 8, !nonnull !0
    %8 = getelementptr inbounds %struct.Bar, %struct.Bar* %7, i64 0, i32 0
    %9 = load i32, i32* %8, align 4
    br label %10
  
  10:                                               ; preds = %1, %5
    %11 = phi i32 [ %9, %5 ], [ 0, %1 ]
    ret i32 %11
  }
  
  attributes #0 = { nounwind uwtable }
  
  !0 = !{}

Running `opt < arg_promo.ll -argpromotion -S > arg_promo.opt2.ll` produces:

  ; ModuleID = '<stdin>'
  source_filename = "<stdin>"
  
  %struct.Foo = type { %struct.Bar*, i8 }
  %struct.Bar = type { i32 }
  
  ; Function Attrs: nounwind uwtable
  define i32 @caller(%struct.Foo* dereferenceable(16) %0) local_unnamed_addr #0 {
    %.idx = getelementptr %struct.Foo, %struct.Foo* %0, i64 0, i32 0
    %.idx.val = load %struct.Bar*, %struct.Bar** %.idx, align 8, !nonnull !0
    %.idx1 = getelementptr %struct.Foo, %struct.Foo* %0, i64 0, i32 1
    %.idx1.val = load i8, i8* %.idx1, align 8
    %2 = call i32 @func(%struct.Bar* %.idx.val, i8 %.idx1.val)
    ret i32 %2
  }
  
  ; Function Attrs: nounwind uwtable
  define internal i32 @func(%struct.Bar* %.0.0.val, i8 %.0.1.val) unnamed_addr #0 {
    %1 = icmp eq i8 %.0.1.val, 0
    br i1 %1, label %5, label %2
  
  2:                                                ; preds = %0
    %3 = getelementptr inbounds %struct.Bar, %struct.Bar* %.0.0.val, i64 0, i32 0
    %4 = load i32, i32* %3, align 4
    br label %5
  
  5:                                                ; preds = %2, %0
    %6 = phi i32 [ %4, %2 ], [ 0, %0 ]
    ret i32 %6
  }
  
  attributes #0 = { nounwind uwtable }
  
  !0 = !{}

Copying `!nonnull` isn't the issue here; the root problem is, the second `load` (%7 from block %5) should not be promoted, since block %5 will not always be executed.

I can try to fix this once I get a chance, but I cannot guarantee an ETA.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D93927/new/

https://reviews.llvm.org/D93927



More information about the llvm-commits mailing list