[PATCH] D47927: [WIP][TargetLowering] Simplify expansion of S{ADD,SUB}O

Roman Lebedev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 8 13:40:45 PDT 2019


lebedev.ri added a comment.

Correct in general case:

  ----------------------------------------
  Name: sadd
    %t = sadd_overflow i8 %LHS, %RHS
    %v0 = extractvalue {i8, i1} %t, 0
    %v1 = extractvalue {i8, i1} %t, 1
  =>
    %t = sadd_overflow i8 %LHS, %RHS
    %v0 = add i8 %LHS, %RHS
    %ResultLowerThanLHS = icmp slt i8 %v0, %LHS
    %ConditionRHS = icmp slt i8 %RHS, 0
    %v1 = xor i1 %ConditionRHS, %ResultLowerThanLHS
  
  Done: 1
  Optimization is correct!
  
  ----------------------------------------
  Name: ssub
    %t = ssub_overflow i8 %LHS, %RHS
    %v0 = extractvalue {i8, i1} %t, 0
    %v1 = extractvalue {i8, i1} %t, 1
  =>
    %t = ssub_overflow i8 %LHS, %RHS
    %v0 = sub i8 %LHS, %RHS
    %ResultLowerThanLHS = icmp slt i8 %v0, %LHS
    %ConditionRHS = icmp sgt i8 %RHS, 0
    %v1 = xor i1 %ConditionRHS, %ResultLowerThanLHS
  
  Done: 1
  Optimization is correct!

Invalid for `undef`:

  ----------------------------------------
  Name: sadd
    %t = sadd_overflow i8 %LHS, %RHS
    %v0 = extractvalue {i8, i1} %t, 0
    %v1 = extractvalue {i8, i1} %t, 1
  =>
    %t = sadd_overflow i8 %LHS, %RHS
    %v0 = add i8 %LHS, %RHS
    %ResultLowerThanLHS = icmp slt i8 %v0, %LHS
    %ConditionRHS = icmp slt i8 %RHS, 0
    %v1 = xor i1 %ConditionRHS, %ResultLowerThanLHS
  
  ERROR: Value mismatch for i1 %v1
  
  Example:
  i8 %LHS = #x00 (0)
  i8 %RHS = undef
  {i8, i1} %t = { #x00 (0), #x0 (0) }     [based on undef value]
  i8 %v0 = undef
  i1 %ResultLowerThanLHS = undef
  i1 %ConditionRHS = undef
  Source value: #x0 (0)
  Target value: #x1 (1)
  
  
  ----------------------------------------
  Name: ssub
    %t = ssub_overflow i8 %LHS, %RHS
    %v0 = extractvalue {i8, i1} %t, 0
    %v1 = extractvalue {i8, i1} %t, 1
  =>
    %t = ssub_overflow i8 %LHS, %RHS
    %v0 = sub i8 %LHS, %RHS
    %ResultLowerThanLHS = icmp slt i8 %v0, %LHS
    %ConditionRHS = icmp sgt i8 %RHS, 0
    %v1 = xor i1 %ConditionRHS, %ResultLowerThanLHS
  
  ERROR: Value mismatch for i1 %v1
  
  Example:
  i8 %LHS = undef
  i8 %RHS = #x00 (0)
  {i8, i1} %t = { #x00 (0), #x0 (0) }     [based on undef value]
  i8 %v0 = undef
  i1 %ResultLowerThanLHS = undef
  i1 %ConditionRHS = #x0 (0)
  Source value: #x0 (0)
  Target value: #x1 (1)


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

https://reviews.llvm.org/D47927





More information about the llvm-commits mailing list