[PATCH] D97092: [ValueTracking] Handle assumes on arguments with context instruction

Philip Reames via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Feb 19 16:41:54 PST 2021


reames added a subscriber: test.
reames added a comment.

I posted another alternative (or maybe a stepping stone towards this one), over in D97099 <https://reviews.llvm.org/D97099>.  It simply sets the context for arguments, and uses the existing mechanism.  The key detail from this patch is that it doesn't attempt to side step the ephemeral value case.

For the ephemeral value case, I'd really like to have a solution which is not non-instruction specific.  If we asking a query on some instruction I, the fact that I is directly used by the assume should not prevent us from inferring facts about that assume.

The test case I'm thinking of is something like the following:

declare void @llvm.assume(i1)

define i32 @test(i1* %p) {

  %a = load i1, i1* %p
  call void @llvm.assume(i1 %a)
  %a.32 = sext i1 %a to i32
  ret i32 %a.32

}

$ opt -enable-new-pm=0 -analyze -scalar-evolution ephemeral.ll 
Printing analysis 'Scalar Evolution Analysis' for function 'test':
Classifying expressions for: @test

  %a = load i1, i1* %p, align 1
  -->  %a U: full-set S: full-set
  %a.32 = sext i1 %a to i32
  -->  (sext i1 %a to i32) U: [-1,1) S: [-1,1) <--- FOCUS HERE

Determining loop execution counts for: @test

>From this, we appear to not be picking up the assume on %a - as I'd expect from the code structure.  Interestingly, instcombine does constant fold this.  I haven't dug in yet, so it's possible I've missed something.

Having said all that, I also don't want to block progress on perfection, and this does seem like progress.  If you want to land this as is, and we can iterate in tree, I'm completely fine with that.  (To be explicit, you can consider this a long winded LGTM.)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97092



More information about the llvm-commits mailing list