Changes in directory llvm/lib/VMCore:

ConstantFolding.cpp updated: 1.103 -> 1.104
---
Log message:

this logic is broken for trunc to bool, replace the folding logic for trunc
completely, as it is trivial.  We should probably do this for the rest of the
cast operations.  This fixes ConstProp/2006-12-01-TruncBoolBug.ll.



---
Diffs of the changes:  (+8 -5)

 ConstantFolding.cpp |   13 ++++++++-----
 1 files changed, 8 insertions(+), 5 deletions(-)


Index: llvm/lib/VMCore/ConstantFolding.cpp
diff -u llvm/lib/VMCore/ConstantFolding.cpp:1.103 
llvm/lib/VMCore/ConstantFolding.cpp:1.104
--- llvm/lib/VMCore/ConstantFolding.cpp:1.103   Thu Nov 30 23:55:25 2006
+++ llvm/lib/VMCore/ConstantFolding.cpp Fri Dec  1 13:22:41 2006
@@ -860,10 +860,10 @@
   // We actually have to do a cast now, but first, we might need to fix up
   // the value of the operand.
   switch (opc) {
+  case Instruction::PtrToInt:
   case Instruction::FPTrunc:
-  case Instruction::Trunc:
   case Instruction::FPExt:
-    break; // floating point input & output, no fixup needed
+    break;
   case Instruction::FPToUI: {
     ConstRules &Rules = ConstRules::get(V, V);
     V = Rules.castToULong(V); // make sure we get an unsigned value first 
@@ -891,9 +891,12 @@
       V = ConstantInt::get(SrcTy->getSignedVersion(), 
                            cast<ConstantIntegral>(V)->getSExtValue());
     break;
-
-  case Instruction::PtrToInt:
-    break;
+  case Instruction::Trunc:
+    // We just handle trunc directly here.  The code below doesn't work for
+    // trunc to bool.
+    if (const ConstantInt *CI = dyn_cast<ConstantInt>(V))
+      return ConstantIntegral::get(DestTy, CI->getZExtValue());
+    return 0;
   case Instruction::BitCast:
     // Check to see if we are casting a pointer to an aggregate to a pointer to
     // the first element.  If so, return the appropriate GEP instruction.



_______________________________________________
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits

Reply via email to