[PATCH] D69753: [InstCombine] Canonicalize ssub.with.overflow to ssub.sat

Dave Green via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Nov 2 13:14:55 PDT 2019


dmgreen created this revision.
dmgreen added reviewers: nikic, lebedev.ri, spatel.
Herald added a subscriber: hiraditya.
Herald added a project: LLVM.
dmgreen added a parent revision: D69252: [InstCombine] Canonicalize sadd.with.overflow to sadd.sat.

Working on top of D69252 <https://reviews.llvm.org/D69252>, this adds canonicalisation patterns for ssub.with.overflow to ssub.sats.

These are the alive patterns being selected, all of which pass:

  Name: SSub_x_lt0
    %ao = ssub_overflow i8 %x, %y
    %a = extractvalue %ao, 0
    %o = extractvalue %ao, 1
    %c = icmp slt i8 %x, 0
    %s = select i1 %c, i8 -128, i8 127
    %x5 = select i1 %o, i8 %s, i8 %a
  =>
    %x5 = ssub_sat %x, %y
  
  Name: SSub_x_lt1
    %ao = ssub_overflow i8 %x, %y
    %a = extractvalue %ao, 0
    %o = extractvalue %ao, 1
    %c = icmp slt i8 %x, -1
    %s = select i1 %c, i8 -128, i8 127
    %x5 = select i1 %o, i8 %s, i8 %a
  =>
    %x5 = ssub_sat %x, %y
  
  Name: SSub_x_lg2
  ; Not valid.
    %ao = ssub_overflow i8 %x, %y
    %a = extractvalue %ao, 0
    %o = extractvalue %ao, 1
    %c = icmp sgt i8 %x, -2
    %s = select i1 %c, i8 127, i8 -128
    %x5 = select i1 %o, i8 %s, i8 %a
  =>
    %x5 = ssub_sat %x, %y
  
  Name: SSub_x_lg1
    %ao = ssub_overflow i8 %x, %y
    %a = extractvalue %ao, 0
    %o = extractvalue %ao, 1
    %c = icmp sgt i8 %x, -1
    %s = select i1 %c, i8 127, i8 -128
    %x5 = select i1 %o, i8 %s, i8 %a
  =>
    %x5 = ssub_sat %x, %y
  
  Name: SSub_y_lt0
    %ao = ssub_overflow i8 %x, %y
    %a = extractvalue %ao, 0
    %o = extractvalue %ao, 1
    %c = icmp slt i8 %y, 0
    %s = select i1 %c, i8 127, i8 -128
    %x5 = select i1 %o, i8 %s, i8 %a
  =>
    %x5 = ssub_sat %x, %y
  
  Name: SSub_y_lt1
    %ao = ssub_overflow i8 %x, %y
    %a = extractvalue %ao, 0
    %o = extractvalue %ao, 1
    %c = icmp slt i8 %y, 1
    %s = select i1 %c, i8 127, i8 -128
    %x5 = select i1 %o, i8 %s, i8 %a
  =>
    %x5 = ssub_sat %x, %y
  
  Name: SSub_y_lg0
    %ao = ssub_overflow i8 %x, %y
    %a = extractvalue %ao, 0
    %o = extractvalue %ao, 1
    %c = icmp sgt i8 %y, 0
    %s = select i1 %c, i8 -128, i8 127
    %x5 = select i1 %o, i8 %s, i8 %a
  =>
    %x5 = ssub_sat %x, %y
  
  Name: SSub_y_lg1
    %ao = ssub_overflow i8 %x, %y
    %a = extractvalue %ao, 0
    %o = extractvalue %ao, 1
    %c = icmp sgt i8 %y, -1
    %s = select i1 %c, i8 -128, i8 127
    %x5 = select i1 %o, i8 %s, i8 %a
  =>
    %x5 = ssub_sat %x, %y


https://reviews.llvm.org/D69753

Files:
  llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
  llvm/test/Transforms/InstCombine/overflow_to_sat.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D69753.227586.patch
Type: text/x-patch
Size: 13061 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191102/fd6935c4/attachment.bin>


More information about the llvm-commits mailing list