[llvm-commits] CVS: llvm/lib/Target/IA64/IA64ISelPattern.cpp

Duraid Madina duraid at octopus.com.au
Mon May 2 00:27:25 PDT 2005



Changes in directory llvm/lib/Target/IA64:

IA64ISelPattern.cpp updated: 1.33 -> 1.34
---
Log message:

support multiplication by constant negative integers

this constmul code is still buggy though, so beware. mul by 7427 is currently
broken, for example. will fix it when I get a moment :)



---
Diffs of the changes:  (+13 -4)

 IA64ISelPattern.cpp |   17 +++++++++++++----
 1 files changed, 13 insertions(+), 4 deletions(-)


Index: llvm/lib/Target/IA64/IA64ISelPattern.cpp
diff -u llvm/lib/Target/IA64/IA64ISelPattern.cpp:1.33 llvm/lib/Target/IA64/IA64ISelPattern.cpp:1.34
--- llvm/lib/Target/IA64/IA64ISelPattern.cpp:1.33	Mon May  2 01:41:13 2005
+++ llvm/lib/Target/IA64/IA64ISelPattern.cpp	Mon May  2 02:27:14 2005
@@ -784,7 +784,7 @@
   bool flippedSign;
   unsigned preliminaryShift=0;
 
-  assert(constant > 0 && "erk, don't multiply by zero or negative nums\n");
+  assert(constant != 0 && "erk, you're trying to multiply by constant zero\n");
 
   // first, we make the constant to multiply by positive
   if(constant<0) {
@@ -832,15 +832,24 @@
   }
 
   // don't forget flippedSign and preliminaryShift!
-  SDOperand finalresult;
+  SDOperand shiftedresult;
   if(preliminaryShift) {
     SDOperand finalshift = ISelDAG->getConstant(preliminaryShift, MVT::i64);
-    finalresult = ISelDAG->getNode(ISD::SHL, MVT::i64,
+    shiftedresult = ISelDAG->getNode(ISD::SHL, MVT::i64,
 	results[ops.size()-1], finalshift);
   } else { // there was no preliminary divide-by-power-of-2 required
-    finalresult = results[ops.size()-1];
+    shiftedresult = results[ops.size()-1];
   }
  
+  SDOperand finalresult;
+  if(flippedSign) { // if we were multiplying by a negative constant:
+    SDOperand zero = ISelDAG->getConstant(0, MVT::i64);
+    // subtract the result from 0 to flip its sign
+    finalresult = ISelDAG->getNode(ISD::SUB, MVT::i64, zero, shiftedresult);
+  } else { // there was no preliminary multiply by -1 required
+    finalresult = shiftedresult;
+  }
+  
   return finalresult; 
 }
 






More information about the llvm-commits mailing list