[llvm-commits] [gcc-plugin] r81210 - /gcc-plugin/trunk/llvm-convert.cpp

Duncan Sands baldrick at free.fr
Tue Sep 8 02:18:10 PDT 2009


Author: baldrick
Date: Tue Sep  8 04:18:10 2009
New Revision: 81210

URL: http://llvm.org/viewvc/llvm-project?rev=81210&view=rev
Log:
According to the gimple verifier, either we are dealing with pointer
types (in which case it shouldn't matter which conversion is done) or
at least one type conversion is useless.  So do the maybe non-useless
conversion.  I suspect this is all pointless since the LLVM types will
be the same in the non pointer case, but hey!

Modified:
    gcc-plugin/trunk/llvm-convert.cpp

Modified: gcc-plugin/trunk/llvm-convert.cpp
URL: http://llvm.org/viewvc/llvm-project/gcc-plugin/trunk/llvm-convert.cpp?rev=81210&r1=81209&r2=81210&view=diff

==============================================================================
--- gcc-plugin/trunk/llvm-convert.cpp (original)
+++ gcc-plugin/trunk/llvm-convert.cpp Tue Sep  8 04:18:10 2009
@@ -3228,10 +3228,6 @@
   tree lhs_ty = TREE_TYPE(lhs);
   tree rhs_ty = TREE_TYPE(rhs);
 
-  if (FLOAT_TYPE_P(lhs_ty))
-    return Builder.CreateFCmp(FCmpInst::Predicate(FPPred),
-                              Emit(lhs, 0), Emit(rhs, 0));
-
   if (TREE_CODE(lhs_ty) == COMPLEX_TYPE) {
     // TODO: Reduce duplication with EmitComplexBinOp.
     const Type *ComplexTy = ConvertType(lhs_ty);
@@ -3265,15 +3261,21 @@
     return Builder.CreateOr(DSTr, DSTi);
   }
 
-  // Handle the integer/pointer cases.
-
-  // Get the compare operands, in the right type. Comparison of struct is not
+  // Get the compare operands in the right type. Comparison of struct is not
   // allowed, so this is safe as we already handled complex (struct) type.
   Value *LHS = Emit(lhs, 0);
   Value *RHS = Emit(rhs, 0);
   bool LHSIsSigned = !TYPE_UNSIGNED(lhs_ty);
   bool RHSIsSigned = !TYPE_UNSIGNED(rhs_ty);
-  RHS = CastToAnyType(RHS, RHSIsSigned, LHS->getType(), LHSIsSigned);
+
+  // If one of the type conversions is useless, perform the other conversion.
+  if (useless_type_conversion_p(lhs_ty, rhs_ty))
+    RHS = CastToAnyType(RHS, RHSIsSigned, LHS->getType(), LHSIsSigned);
+  else
+    LHS = CastToAnyType(LHS, LHSIsSigned, RHS->getType(), RHSIsSigned);
+
+  if (FLOAT_TYPE_P(lhs_ty))
+    return Builder.CreateFCmp(FCmpInst::Predicate(FPPred), LHS, RHS);
 
   // Determine which predicate to use based on signedness.
   ICmpInst::Predicate pred = ICmpInst::Predicate(LHSIsSigned ? SIOpc : UIOpc);





More information about the llvm-commits mailing list