[PATCH] D76611: [SCCP] Use ranges for predicate info conditions.

Florian Hahn via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 25 15:11:31 PDT 2020


fhahn updated this revision to Diff 252683.
fhahn added a comment.

In D76611#1940012 <https://reviews.llvm.org/D76611#1940012>, @efriedma wrote:

> Hang on, is this actually safe?
>
> If we compute a predicate based on a possibly-undef value, and branch based on that, does the predicate actually mean anything?


There are 2 cases IIUC that may be undef: the value we derive a bound for and the bound. I think in terms of the bound value, we should be safe, as we will go to overdefined for ranges that are merged with undef and effectively remove the information from the bound.

I think for now it should be safe as well if the value we derive the bound for may be undef, because the only place we actually use range information for simplification is at compares and there we always replace an icmp with a constant.

And I am not sure if it would be safe in general to replace a value with a different value based on range info in any case. E.g. consider

  define void @foo(i32 %a) {
  entry:
    %bc.1 = icmp ult i32 %a, 15
    br i1 %bc.1, label %true, label %false
  
  true:
    %f.1 = icmp eq i32 %a, 128
    call void @use(i1 %f.1)
  
    %p.127 = and i32 %a, 15
    call void @use.i32(i32 %p.127)
    ret void
  
  false:
    ret void
  }

We can use the range info in the above to remove %f.1, but we cannot use it to remove the %p.127 = and...., as %a could be undef. CVP currently gets this wrong, besides other things. If we want to remove the and, we would need to insert an extra freeze I think.

Does that make sense?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76611

Files:
  llvm/lib/Transforms/Scalar/SCCP.cpp
  llvm/test/Transforms/SCCP/conditions-ranges-with-undef.ll
  llvm/test/Transforms/SCCP/conditions-ranges.ll
  llvm/test/Transforms/SCCP/ip-constant-ranges.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D76611.252683.patch
Type: text/x-patch
Size: 17111 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200325/6f1e4a04/attachment.bin>


More information about the llvm-commits mailing list