[PATCH] D41136: [EarlyCSE] recognize commuted and swapped variants of min/max as equivalent (PR35642)

Sanjay Patel via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 14 09:04:18 PST 2017


spatel added a comment.

On closer inspection, I think matchSelectPattern is either not sufficient or broken because it doesn't handle -0.0 as we would require here:

  declare void @self_destruct_if_neg_zero(double)  
  define double @fmin_any_ordered_commute(double %x, double %y) {
    %cmp1 = fcmp nnan olt double %x, %y                            ; if x=+0.0 and y=-0.0, returns false
    %cmp2 = fcmp nnan olt double %y, %x                            ; if x=+0.0 and y=-0.0, returns false
    %neg_zero_if_false = select i1 %cmp1, double %x, double %y     ; returns -0.0
    %pos_zero_if_false = select i1 %cmp2, double %y, double %x     ; returns +0.0
    call void @self_destruct_if_neg_zero(double %pos_zero_if_false)
    ret double %neg_zero_if_false
  }

If we use what is returned by matchSelectPattern ( {SPF_FMINNUM, SPNB_RETURNS_ANY, false} ), we get:

$ ./opt -early-cse fminmax.ll -S

  define double @fmin_any_ordered_commute(double %x, double %y) {
    %cmp1 = fcmp nnan olt double %x, %y
    %cmp2 = fcmp nnan olt double %y, %x
    %neg_zero_if_false = select i1 %cmp1, double %x, double %y
    call void @self_destruct_if_neg_zero(double %neg_zero_if_false)  ; boom!
    ret double %neg_zero_if_false
  }


Repository:
  rL LLVM

https://reviews.llvm.org/D41136





More information about the llvm-commits mailing list