[PATCH] D74484: [AggressiveInstCombine] Add support for ICmp instr that feeds a select intsr's condition operand.

Sanjay Patel via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 31 11:26:26 PDT 2020


spatel added a comment.

In D74484#1951878 <https://reviews.llvm.org/D74484#1951878>, @aymanmus wrote:

> Just checked the patch @spatel mentioned.
>  Doesn't really help with the cases provided here.


Thanks for checking. In that case, it would be helpful to comment on which of the tests are the real motivation (and possibly remove the tests that are not canonical IR).
For example, -instcombine alone is enough to reduce these:

  define dso_local i16 @cmp_shrink_select_not_cmp(i8 %a, i8 %b, i32 %c, i32 %d) {
    %conv = sext i8 %a to i32
    %conv2 = sext i8 %b to i32
    %cmp = icmp slt i32 %c, %d
    %cond = select i1 %cmp, i32 %conv2, i32 %conv
    %conv4 = trunc i32 %cond to i16
    ret i16 %conv4
  }
  
  define i16 @cmp_select_bigConst_cmp(i8 %a, i8 %b, i8 %c) {
    %conv = sext i8 %a to i32
    %conv2 = sext i8 %b to i32
    %conv3 = sext i8 %c to i32
    %cmp = icmp slt i32 %conv3, 70000
    %cond = select i1 %cmp, i32 %conv2, i32 %conv
    %conv4 = trunc i32 %cond to i16
    ret i16 %conv4
  }



  $ ./opt -instcombine cmpsel.ll -S
  
  define dso_local i16 @cmp_shrink_select_not_cmp(i8 %a, i8 %b, i32 %c, i32 %d) {
  entry:
    %cmp = icmp slt i32 %c, %d
    %cond.v = select i1 %cmp, i8 %b, i8 %a
    %conv4 = sext i8 %cond.v to i16
    ret i16 %conv4
  }
  
  define i16 @cmp_select_bigConst_cmp(i8 %a, i8 %b, i8 %c) {
    %conv4 = sext i8 %b to i16
    ret i16 %conv4
  }


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

https://reviews.llvm.org/D74484





More information about the llvm-commits mailing list