[PATCH] D60846: [ValueTracking] Improve isKnowNonZero for Ints

Nikita Popov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu May 9 13:53:58 PDT 2019


nikic added a comment.

Here's a slightly cleaned up version of the reproducer:

  define void @test(i1* %p) {
  entry:
    br label %loop
  
  loop:                                             ; preds = %common, %entry
    %i = phi i16 [ 0, %entry ], [ %i.inc, %common ]
    %is_zero = icmp eq i16 %i, 0
    br i1 %is_zero, label %common, label %non_zero
  
  non_zero:                                         ; preds = %loop
    %is_one = icmp eq i16 %i, 1
    store i1 %is_one, i1* %p
    br label %common
  
  common:                                           ; preds = %non_zero, %loop
    %i.inc = add i16 %i, 1
    %loop_cond = icmp ult i16 %i.inc, 2
    br i1 %loop_cond, label %loop, label %exit
  
  exit:                                             ; preds = %common
    ret void
  }

The `%is_one` is incorrectly optimized to false. I've been trying to come up with some variation that makes it fail without this patch, but no luck so far (something assume() based should be possible in theory, but it's very hard to actually construct something.)


Repository:
  rL LLVM

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

https://reviews.llvm.org/D60846





More information about the llvm-commits mailing list