[PATCH] D60395: [InstCombine] canonicalize sdiv with NEG operand

Roman Lebedev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Apr 7 23:30:38 PDT 2019


lebedev.ri requested changes to this revision.
lebedev.ri added a comment.
This revision now requires changes to proceed.

Looks promising.



================
Comment at: llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp:1028-1029
+  Value *Y;
+  if (match(&I, m_SDiv(m_OneUse(m_NSWSub(m_Zero(), m_Value(X))), m_Value(Y))) ||
+    match(&I, m_SDiv(m_Value(X), m_OneUse(m_NSWSub(m_Zero(), m_Value(Y))))))
+    return BinaryOperator::CreateNeg(
----------------
It's not commutative like that.
```
----------------------------------------
Optimization: -X / Y  to  -(X / Y)
Precondition: true
  %t0 = sub nsw i8 0, %x
  %r = sdiv i8 %t0, %y
=>
  %n0 = sdiv i8 %x, %y
  %r = sub i8 0, %n0

Done: 1
Optimization is correct!

----------------------------------------
Optimization: X / -Y --> -(X / Y)
Precondition: true
  %t0 = sub nsw i8 0, %y
  %r = sdiv i8 %x, %t0
=>
  %n0 = sdiv i8 %x, %y
  %r = sub i8 0, %n0


ERROR: Domain of definedness of Target is smaller than Source's for i8 %r

Example:
%y i8 = 0xFF (255, -1)
%x i8 = 0x80 (128, -128)
%t0 i8 = 0x01 (1)
%n0 i8 = 0x80 (128, -128)
Source value: 0x80 (128, -128)
Target value: undef

```
(You could use https://rise4fun.com/Alive, but it appears down for the moment?)


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

https://reviews.llvm.org/D60395





More information about the llvm-commits mailing list