[PATCH] D112016: [IR] Introduce load assume operand bundle

Arthur Eubanks via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 18 13:34:24 PDT 2021


aeubanks added a comment.

In D112016#3071099 <https://reviews.llvm.org/D112016#3071099>, @nikic wrote:

> As long as the load is speculatable, it should count as an ephemeral value and be considered as free by the inliner at least.

I'm not seeing that:

  $ cat /tmp/a.ll
  declare i8 @f(i8* %p)
  declare void @llvm.assume(i1)
  
  declare void @constructor(i8*)
  declare void @foo(i8*)
  
  define i8 @g1(i8* %p) {
          call void @constructor(i8* %p)
          %i = load i8, i8* %p
          %c = icmp eq i8 %i, 2
          call void @llvm.assume(i1 %c)
          %r = call i8 @f(i8* %p)
          ret i8 %r
  }
  
  define i8 @wrapper1(i8* %p) {
          %r = call i8 @g1(i8* %p)
          ret i8 %r
  }
  
  define i8 @g2(i8* %p) {
          call void @constructor(i8* %p)
          call void @llvm.assume(i1 true) ["load"(i8* %p, i8 2)]
          %r = call i8 @f(i8* %p)
          ret i8 %r
  }
  
  define i8 @wrapper2(i8* %p) {
          %r = call i8 @g2(i8* %p)
          ret i8 %r
  }
  
  $ ./build/rel/bin/opt -passes='print<inline-cost>' -disable-output /tmp/a.ll
        Analyzing call of g1... (caller:wrapper1)
  define i8 @g1(i8* %p) {
  ; cost before = -35, cost after = 0, threshold before = 674, threshold after = 674, cost delta = 35
    call void @constructor(i8* %p)
  ; cost before = 0, cost after = 5, threshold before = 674, threshold after = 674, cost delta = 5
    %i = load i8, i8* %p, align 1
  ; No analysis for the instruction
    %c = icmp eq i8 %i, 2
  ; No analysis for the instruction
    call void @llvm.assume(i1 %c)
  ; cost before = 5, cost after = 40, threshold before = 674, threshold after = 674, cost delta = 35
    %r = call i8 @f(i8* %p)
  ; cost before = 40, cost after = 40, threshold before = 674, threshold after = 674, cost delta = 0
    ret i8 %r
  }
        NumConstantArgs: 0
        NumConstantOffsetPtrArgs: 1
        NumAllocaArgs: 0
        NumConstantPtrCmps: 0
        NumConstantPtrDiffs: 0
        NumInstructionsSimplified: 1
        NumInstructions: 4
        SROACostSavings: 0
        SROACostSavingsLost: 0
        LoadEliminationCost: 0
        ContainsNoDuplicateCall: 0
        Cost: 40
        Threshold: 337
        Analyzing call of g2... (caller:wrapper2)
  define i8 @g2(i8* %p) {
  ; cost before = -35, cost after = 0, threshold before = 674, threshold after = 674, cost delta = 35
    call void @constructor(i8* %p)
  ; No analysis for the instruction
    call void @llvm.assume(i1 true) [ "load"(i8* %p, i8 2) ]
  ; cost before = 0, cost after = 35, threshold before = 674, threshold after = 674, cost delta = 35
    %r = call i8 @f(i8* %p)
  ; cost before = 35, cost after = 35, threshold before = 674, threshold after = 674, cost delta = 0
    ret i8 %r
  }
        NumConstantArgs: 0
        NumConstantOffsetPtrArgs: 1
        NumAllocaArgs: 0
        NumConstantPtrCmps: 0
        NumConstantPtrDiffs: 0
        NumInstructionsSimplified: 1
        NumInstructions: 3
        SROACostSavings: 0
        SROACostSavingsLost: 0
        LoadEliminationCost: 0
        ContainsNoDuplicateCall: 0
        Cost: 35
        Threshold: 337


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D112016



More information about the llvm-commits mailing list