[llvm-commits] [llvm] r125393 - in /llvm/trunk: lib/VMCore/ConstantFold.cpp test/Transforms/InstCombine/bitcast-vec-uniform.ll test/Transforms/InstCombine/fold-vector-select.ll

Rotem, Nadav nadav.rotem at intel.com
Mon Feb 14 13:56:57 PST 2011


I started by looking at adding alone support for constants. I started by adding support for float/double inside the Constant function. A change to APFloat is also possible but more complex. What do you think ?


Index: Constants.cpp
===================================================================
--- Constants.cpp	(revision 3012)
+++ Constants.cpp	(working copy)
@@ -91,6 +91,16 @@
     return ConstantInt::get(Ty->getContext(),
                             APInt::getAllOnesValue(ITy->getBitWidth()));
   
+  unsigned t = 0xFFFFFFFF;
+  unsigned long long dt = 0xFFFFFFFFFFFFFFFF;
+  float F = reinterpret_cast<float&>(t);
+  if (Ty->isFloatTy()) return ConstantFP::get(Ty->getContext(),
+    APFloat(F));
+
+  double D = reinterpret_cast<double&>(dt);
+  if (Ty->isDoubleTy()) return ConstantFP::get(Ty->getContext(),
+    APFloat(D));
+
   std::vector<Constant*> Elts;
   const VectorType *VTy = cast<VectorType>(Ty);
   Elts.resize(VTy->getNumElements(), getAllOnesValue(VTy->getElementType()));



-----Original Message-----
From: llvm-commits-bounces at cs.uiuc.edu [mailto:llvm-commits-bounces at cs.uiuc.edu] On Behalf Of Nick Lewycky
Sent: Monday, February 14, 2011 00:06
To: Duncan Sands
Cc: llvm-commits at cs.uiuc.edu
Subject: Re: [llvm-commits] [llvm] r125393 - in /llvm/trunk: lib/VMCore/ConstantFold.cpp test/Transforms/InstCombine/bitcast-vec-uniform.ll test/Transforms/InstCombine/fold-vector-select.ll

Duncan Sands wrote:
> Hi Nadav,
>
>> Thank you for catching this.
>>
>> The patch below fixes the problem. If it looks good to you I will commit it.
>
> why not teach getAllOnesValue to handle floating point types instead?

Further, it seems that if we're going to have Constant::getAllOnesValue 
then we should also have Constant->isAllOnesValue().

Nick
_______________________________________________
llvm-commits mailing list
llvm-commits at cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
---------------------------------------------------------------------
Intel Israel (74) Limited

This e-mail and any attachments may contain confidential material for
the sole use of the intended recipient(s). Any review or distribution
by others is strictly prohibited. If you are not the intended
recipient, please contact the sender and delete all copies.





More information about the llvm-commits mailing list