[llvm-commits] CVS: llvm/lib/CodeGen/PreOpts/PreSelection.cpp

Vikram Adve vadve at cs.uiuc.edu
Fri Sep 27 09:25:01 PDT 2002


Changes in directory llvm/lib/CodeGen/PreOpts:

PreSelection.cpp updated: 1.1 -> 1.2

---
Log message:

Decompose FP-to-UInt casts into FP-to-ULong-toUInt.


---
Diffs of the changes:

Index: llvm/lib/CodeGen/PreOpts/PreSelection.cpp
diff -u llvm/lib/CodeGen/PreOpts/PreSelection.cpp:1.1 llvm/lib/CodeGen/PreOpts/PreSelection.cpp:1.2
--- llvm/lib/CodeGen/PreOpts/PreSelection.cpp:1.1	Thu Sep 19 19:29:28 2002
+++ llvm/lib/CodeGen/PreOpts/PreSelection.cpp	Fri Sep 27 09:24:45 2002
@@ -146,6 +146,7 @@
     void visitInstruction(Instruction &I);   // common work for every instr. 
     void visitGetElementPtrInst(GetElementPtrInst &I);
     void visitLoadInst(LoadInst &I);
+    void visitCastInst(CastInst &I);
     void visitStoreInst(StoreInst &I);
 
     // Helper functions for visiting operands of every instruction
@@ -225,6 +226,33 @@
 
   // Perform other transformations common to all instructions
   visitInstruction(I);
+}
+
+
+// Cast instructions: make multi-step casts explicit
+// -- float/double to uint32_t:
+//    If target does not have a float-to-unsigned instruction, we
+//    need to convert to uint64_t and then to uint32_t, or we may
+//    overflow the signed int representation for legal uint32_t
+//    values.  Expand this without checking target.
+// 
+void
+PreSelection::visitCastInst(CastInst &I)
+{ 
+  CastInst* castI = NULL;
+
+  // Check for a global and put its address into a register before this instr
+  if (I.getType() == Type::UIntTy &&
+      I.getOperand(0)->getType()->isFloatingPoint())
+    { // insert a cast-fp-to-long before I, and then replace the operand of I
+      castI = new CastInst(I.getOperand(0), Type::LongTy, "fp2Long2Uint", &I);
+      I.setOperand(0, castI);           // replace fp operand with long
+    }
+
+  // Perform other transformations common to all instructions
+  visitInstruction(I);
+  if (castI)
+    visitInstruction(*castI);
 }
 
 





More information about the llvm-commits mailing list