[PATCH] D112895: [CVP] Canonicalize signed relational comparisons of scalar integers to unsigned comparison predicates

Artur Pilipenko via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 23 11:40:42 PST 2021


apilipenko added a comment.

This change broke the ability to discard checks in some cases. Consider this example:

  define i1 @test1(i32 %a, i32* %b_ptr) {
    %b = load i32, i32* %b_ptr, align 8, !range !{i32 0, i32 2147483646}
    %c1 = icmp slt i32 %a, %b
    br i1 %c1, label %exit, label %cont.1
  
  cont.1:
    %c2 = icmp slt i32 %a, 0
    br i1 %c2, label %exit, label %cont.2
  
  cont.2:
    %c3 = icmp sgt i32 %b, %a
    ret i1 %c3
  
  exit:
    ret i1 false
  }

In this form %c3 check is trivially constant foldable (from the dominating %c1 check). For example, EarlyCSE can discard it. With this change, CVP would rewrite %c3 to an unsigned form.

  define i1 @test1(i32 %a, i32* %b_ptr) {
    %b = load i32, i32* %b_ptr, align 8, !range !0
    %c1 = icmp slt i32 %a, %b
    br i1 %c1, label %exit, label %cont.1
  
  cont.1:                                           ; preds = %0
    br i1 false, label %exit, label %cont.2
  
  cont.2:                                           ; preds = %cont.1
    %c3 = icmp ugt i32 %b, %a
    ret i1 %c3
  
  exit:                                             ; preds = %cont.1, %0
    ret i1 false
  }
  
  !0 = !{i32 0, i32 2147483646}

The check %c is still optimizable, but currently, we don't have anything in O3 <https://reviews.llvm.org/owners/package/3/> which eliminates it.

Any suggestions for the best place to handle it?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D112895



More information about the llvm-commits mailing list