support x * (c1 + c2) where c1 and c2 are pow2s. special case for c2 == 4
authorAndrew Lenharth <andrewl@lenharth.org>
Mon, 3 Apr 2006 04:19:17 +0000 (04:19 +0000)
committerAndrew Lenharth <andrewl@lenharth.org>
Mon, 3 Apr 2006 04:19:17 +0000 (04:19 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@27370 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/Alpha/AlphaISelDAGToDAG.cpp
lib/Target/Alpha/AlphaInstrInfo.td

index 03e6246c01778811492e26e7e15e560d0d67fbe4..e16411f5e3c051a453ef7a4d3628cfa3a8f76344 100644 (file)
@@ -77,7 +77,7 @@ namespace {
       uint64_t complow = 1 << (63 - at);
       uint64_t comphigh = 1 << (64 - at);
       //std::cerr << x << ":" << complow << ":" << comphigh << "\n";
-      if (abs(complow - x) < abs(comphigh - x))
+      if (abs(complow - x) <= abs(comphigh - x))
         return complow;
       else
         return comphigh;
index 1422466e3f373511ee0cbd064099d32e3157a400..5fa770a0c7ee9edad23d02357d2e16cee708df24 100644 (file)
@@ -60,6 +60,10 @@ def iZAPX : SDNodeXForm<imm, [{ // get imm to ZAPi
 def nearP2X : SDNodeXForm<imm, [{
   return getI64Imm(Log2_64(getNearPower2((uint64_t)N->getValue())));
 }]>;
+def nearP2RemX : SDNodeXForm<imm, [{
+  uint64_t x = abs(N->getValue() - getNearPower2((uint64_t)N->getValue()));
+  return getI64Imm(Log2_64(x));
+}]>;
 
 def immUExt8  : PatLeaf<(imm), [{ //imm fits in 8 bit zero extended field
   return (uint64_t)N->getValue() == (uint8_t)N->getValue();
@@ -84,26 +88,39 @@ def immFPZ  : PatLeaf<(fpimm), [{ //the only fpconstant nodes are +/- 0.0
   return true;
 }]>;
 def immRem1 : PatLeaf<(imm), [{
-  return (int64_t)getNearPower2((uint64_t)N->getValue()) - (int64_t)N->getValue() == -1;
+  return N->getValue() - getNearPower2((uint64_t)N->getValue()) == 1;
 }]>;
 def immRem3 : PatLeaf<(imm), [{
-  return (int64_t)getNearPower2((uint64_t)N->getValue()) - (int64_t)N->getValue() == -3;
+  return N->getValue() - getNearPower2((uint64_t)N->getValue()) == 3;
+}]>;
+def immRem4 : PatLeaf<(imm), [{
+  return N->getValue() - getNearPower2((uint64_t)N->getValue()) == 4;
 }]>;
 def immRem5 : PatLeaf<(imm), [{
-  return (int64_t)getNearPower2((uint64_t)N->getValue()) - (int64_t)N->getValue() == -5;
+  return N->getValue() - getNearPower2((uint64_t)N->getValue()) == 5;
 }]>;
 def immRem1n : PatLeaf<(imm), [{
-  return (int64_t)getNearPower2((uint64_t)N->getValue()) - N->getValue() == 1;
+  return getNearPower2((uint64_t)N->getValue()) - N->getValue() == 1;
 }]>;
 def immRem3n : PatLeaf<(imm), [{
-  return (int64_t)getNearPower2((uint64_t)N->getValue()) - N->getValue() == 3;
+  return getNearPower2((uint64_t)N->getValue()) - N->getValue() == 3;
+}]>;
+def immRem4n : PatLeaf<(imm), [{
+  return getNearPower2((uint64_t)N->getValue()) - N->getValue() == 4;
 }]>;
 def immRem5n : PatLeaf<(imm), [{
-  return (int64_t)getNearPower2((uint64_t)N->getValue()) - N->getValue() == 5;
+  return getNearPower2((uint64_t)N->getValue()) - N->getValue() == 5;
+}]>;
+def immRemP2n : PatLeaf<(imm), [{
+  return isPowerOf2_64(getNearPower2((uint64_t)N->getValue()) - N->getValue());
+}]>;
+def immRemP2 : PatLeaf<(imm), [{
+  return isPowerOf2_64(N->getValue() - getNearPower2((uint64_t)N->getValue()));
 }]>;
 def immUExt8ME : PatLeaf<(imm), [{ //use this imm for mulqi
-  int64_t d = (int64_t)getNearPower2((uint64_t)N->getValue()) - N->getValue();
-  switch (abs(d)) {
+  int64_t d =  abs((int64_t)N->getValue() - (int64_t)getNearPower2((uint64_t)N->getValue()));
+  if (isPowerOf2_64(d)) return false;
+  switch (d) {
     case 1: case 3: case 5: return false; 
     default: return (uint64_t)N->getValue() == (uint8_t)N->getValue();
   };
@@ -915,6 +932,10 @@ def : Pat<(mul GPRC:$RA, immRem3:$imm),
           (ADDQ (SL GPRC:$RA, (nearP2X immRem3:$imm)), (S4SUBQ GPRC:$RA, GPRC:$RA))>;
 def : Pat<(mul GPRC:$RA, immRem5:$imm),
           (ADDQ (SL GPRC:$RA, (nearP2X immRem5:$imm)), (S4ADDQ GPRC:$RA, GPRC:$RA))>;
+def : Pat<(mul GPRC:$RA, immRem4:$imm),
+          (S4ADDQ GPRC:$RA, (SL GPRC:$RA, (nearP2X immRem4:$imm)))>;
+def : Pat<(mul GPRC:$RA, immRemP2:$imm),
+          (ADDQ (SL GPRC:$RA, (nearP2X immRemP2:$imm)), (SLi GPRC:$RA, (nearP2RemX immRemP2:$imm)))>;
 
 def : Pat<(mul GPRC:$RA, immRem1n:$imm), 
           (SUBQ (SL GPRC:$RA, (nearP2X immRem1n:$imm)), GPRC:$RA)>;
@@ -922,4 +943,5 @@ def : Pat<(mul GPRC:$RA, immRem3n:$imm),
           (SUBQ (SL GPRC:$RA, (nearP2X immRem3n:$imm)), (S4SUBQ GPRC:$RA, GPRC:$RA))>;
 def : Pat<(mul GPRC:$RA, immRem5n:$imm),
           (SUBQ (SL GPRC:$RA, (nearP2X immRem5n:$imm)), (S4ADDQ GPRC:$RA, GPRC:$RA))>;
-
+def : Pat<(mul GPRC:$RA, immRemP2n:$imm),
+          (SUBQ (SL GPRC:$RA, (nearP2X immRemP2n:$imm)), (SLi GPRC:$RA, (nearP2RemX immRemP2n:$imm)))>;