[PATCH] InstSimplify: Optimize using dividend in sdiv

David Majnemer david.majnemer at gmail.com
Mon May 19 07:24:22 PDT 2014


Closed by commit rL208999 (authored by @majnemer).

http://reviews.llvm.org/D3795

Files:
  llvm/trunk/lib/Analysis/InstructionSimplify.cpp
  llvm/trunk/test/Transforms/InstSimplify/compare.ll

Index: llvm/trunk/test/Transforms/InstSimplify/compare.ll
===================================================================
--- llvm/trunk/test/Transforms/InstSimplify/compare.ll
+++ llvm/trunk/test/Transforms/InstSimplify/compare.ll
@@ -817,3 +817,12 @@
 ; CHECK-LABEL: @compare_always_false_ne
 ; CHECK-NEXT: ret i1 true
 }
+
+define i1 @compare_dividend(i32 %a) {
+  %div = sdiv i32 2, %a
+  %cmp = icmp eq i32 %div, 3
+  ret i1 %cmp
+
+; CHECK-LABEL: @compare_dividend
+; CHECK-NEXT: ret i1 false
+}
Index: llvm/trunk/lib/Analysis/InstructionSimplify.cpp
===================================================================
--- llvm/trunk/lib/Analysis/InstructionSimplify.cpp
+++ llvm/trunk/lib/Analysis/InstructionSimplify.cpp
@@ -2020,6 +2020,10 @@
       APInt NegOne = APInt::getAllOnesValue(Width);
       if (!CI2->isZero())
         Upper = NegOne.udiv(CI2->getValue()) + 1;
+    } else if (match(LHS, m_SDiv(m_ConstantInt(CI2), m_Value()))) {
+      // 'sdiv CI2, x' produces [-|CI2|, |CI2|].
+      Upper = CI2->getValue().abs() + 1;
+      Lower = (-Upper) + 1;
     } else if (match(LHS, m_SDiv(m_Value(), m_ConstantInt(CI2)))) {
       // 'sdiv x, CI2' produces [INT_MIN / CI2, INT_MAX / CI2].
       APInt IntMin = APInt::getSignedMinValue(Width);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D3795.9567.patch
Type: text/x-patch
Size: 1266 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140519/eeec6e13/attachment.bin>


More information about the llvm-commits mailing list