From fb77c05dfda27ad52df7d9689d0193746c36ca52 Mon Sep 17 00:00:00 2001 From: Alexey Prokhin Date: Thu, 15 Sep 2011 12:04:13 +0400 Subject: [PATCH] DMD Issue 3632 - modify float is float to do a bitwise compare --- druntime | 2 +- gen/binops.cpp | 41 +++++++++++++++++++++++++++++++++++------ gen/complex.cpp | 44 ++++++++++++++++++++++++++++---------------- gen/complex.h | 1 + gen/llvmhelpers.h | 1 + phobos | 2 +- 6 files changed, 67 insertions(+), 24 deletions(-) diff --git a/druntime b/druntime index fba10fa9..e69646d6 160000 --- a/druntime +++ b/druntime @@ -1 +1 @@ -Subproject commit fba10fa9f686f8d1d0be0099daedc3c9162a106a +Subproject commit e69646d6cded1209247955343dccd1cdb90903fd diff --git a/gen/binops.cpp b/gen/binops.cpp index 892dece5..c23707da 100644 --- a/gen/binops.cpp +++ b/gen/binops.cpp @@ -7,6 +7,7 @@ #include "gen/dvalue.h" #include "gen/logger.h" #include "gen/complex.h" +#include "gen/llvmhelpers.h" ////////////////////////////////////////////////////////////////////////////// @@ -108,10 +109,7 @@ LLValue* DtoBinNumericEquals(Loc loc, DValue* lhs, DValue* rhs, TOK op) assert(t->isfloating()); Logger::println("numeric equality"); - LLValue* lv = lhs->getRVal(); - LLValue* rv = rhs->getRVal(); LLValue* res = 0; - if (t->iscomplex()) { Logger::println("complex"); @@ -120,11 +118,42 @@ LLValue* DtoBinNumericEquals(Loc loc, DValue* lhs, DValue* rhs, TOK op) else if (t->isfloating()) { Logger::println("floating"); - res = (op == TOKidentity || op == TOKequal) - ? gIR->ir->CreateFCmpOEQ(lv,rv,"tmp") - : gIR->ir->CreateFCmpUNE(lv,rv,"tmp"); + res = DtoBinFloatsEquals(loc, lhs, rhs, op); } assert(res); return res; } + +////////////////////////////////////////////////////////////////////////////// + +LLValue* DtoBinFloatsEquals(Loc loc, DValue* lhs, DValue* rhs, TOK op) +{ + LLValue* res = 0; +#if DMDV2 + if (op == TOKequal) { + res = gIR->ir->CreateFCmpOEQ(lhs->getRVal(), rhs->getRVal(), "tmp"); + } else if (op == TOKnotequal) { + res = gIR->ir->CreateFCmpUNE(lhs->getRVal(), rhs->getRVal(), "tmp"); + } else { + llvm::ICmpInst::Predicate cmpop; + if (op == TOKidentity) + cmpop = llvm::ICmpInst::ICMP_EQ; + else + cmpop = llvm::ICmpInst::ICMP_NE; + + LLValue* sz = DtoConstSize_t(getTypeStoreSize(DtoType(lhs->getType()))); + LLValue* val = DtoMemCmp(makeLValue(loc, lhs), makeLValue(loc, rhs), sz); + res = gIR->ir->CreateICmp(cmpop, val, LLConstantInt::get(val->getType(), 0, false), "tmp"); + } +#else + LLValue* lv = lhs->getRVal(); + LLValue* rv = rhs->getRVal(); + res = (op == TOKidentity || op == TOKequal) ? + gIR->ir->CreateFCmpOEQ(lv, rv, "tmp") : + gIR->ir->CreateFCmpUNE(lv, rv, "tmp"); + +#endif + assert(res); + return res; +} diff --git a/gen/complex.cpp b/gen/complex.cpp index 64b6867e..170b2154 100644 --- a/gen/complex.cpp +++ b/gen/complex.cpp @@ -125,7 +125,7 @@ void DtoComplexSet(LLValue* c, LLValue* re, LLValue* im) ////////////////////////////////////////////////////////////////////////////////////////// -void DtoGetComplexParts(Loc& loc, Type* to, DValue* val, LLValue*& re, LLValue*& im) +void DtoGetComplexParts(Loc& loc, Type* to, DValue* val, DValue*& re, DValue*& im) { Type* baserety; Type* baseimty; @@ -149,21 +149,30 @@ void DtoGetComplexParts(Loc& loc, Type* to, DValue* val, LLValue*& re, LLValue*& if (t->iscomplex()) { DValue* v = DtoCastComplex(loc, val, to); if (to->iscomplex()) { - re = gIR->ir->CreateExtractValue(v->getRVal(), 0, ".re_part"); - im = gIR->ir->CreateExtractValue(v->getRVal(), 1, ".im_part"); + if (v->isLVal()) { + LLValue *reVal = DtoGEP(v->getLVal(), DtoConstInt(0), DtoConstInt(0), ".re_part"); + LLValue *imVal = DtoGEP(v->getLVal(), DtoConstInt(0), DtoConstInt(1), ".im_part"); + re = new DVarValue(baserety, reVal); + im = new DVarValue(baseimty, imVal); + } else { + LLValue *reVal = gIR->ir->CreateExtractValue(v->getRVal(), 0, ".re_part"); + LLValue *imVal = gIR->ir->CreateExtractValue(v->getRVal(), 1, ".im_part"); + re = new DImValue(baserety, reVal); + im = new DImValue(baseimty, imVal); + } } else DtoGetComplexParts(loc, to, v, re, im); } else if (t->isimaginary()) { re = NULL; - im = DtoCastFloat(loc, val, baseimty)->getRVal(); + im = DtoCastFloat(loc, val, baseimty); } else if (t->isfloating()) { - re = DtoCastFloat(loc, val, baserety)->getRVal(); + re = DtoCastFloat(loc, val, baserety); im = NULL; } else if (t->isintegral()) { - re = DtoCastInt(loc, val, baserety)->getRVal(); + re = DtoCastInt(loc, val, baserety); im = NULL; } else { @@ -173,6 +182,16 @@ void DtoGetComplexParts(Loc& loc, Type* to, DValue* val, LLValue*& re, LLValue*& ////////////////////////////////////////////////////////////////////////////////////////// +void DtoGetComplexParts(Loc& loc, Type* to, DValue* val, LLValue*& re, LLValue*& im) +{ + DValue *dre, *dim; + DtoGetComplexParts(loc, to, val, dre, dim); + re = dre ? dre->getRVal() : 0; + im = dim ? dim->getRVal() : 0; +} + +////////////////////////////////////////////////////////////////////////////////////////// + DValue* DtoComplexAdd(Loc& loc, Type* type, DValue* lhs, DValue* rhs) { llvm::Value *lhs_re, *lhs_im, *rhs_re, *rhs_im, *res_re, *res_im; @@ -396,23 +415,16 @@ LLValue* DtoComplexEquals(Loc& loc, TOK op, DValue* lhs, DValue* rhs) { Type* type = lhs->getType(); - llvm::Value *lhs_re, *lhs_im, *rhs_re, *rhs_im; + DValue *lhs_re, *lhs_im, *rhs_re, *rhs_im; // lhs values DtoGetComplexParts(loc, type, lhs, lhs_re, lhs_im); // rhs values DtoGetComplexParts(loc, type, rhs, rhs_re, rhs_im); - // select predicate - llvm::FCmpInst::Predicate cmpop; - if (op == TOKequal || op == TOKidentity) - cmpop = llvm::FCmpInst::FCMP_OEQ; - else - cmpop = llvm::FCmpInst::FCMP_UNE; - // (l.re==r.re && l.im==r.im) or (l.re!=r.re || l.im!=r.im) - LLValue* b1 = gIR->ir->CreateFCmp(cmpop, lhs_re, rhs_re, "tmp"); - LLValue* b2 = gIR->ir->CreateFCmp(cmpop, lhs_im, rhs_im, "tmp"); + LLValue* b1 = DtoBinFloatsEquals(loc, lhs_re, rhs_re, op); + LLValue* b2 = DtoBinFloatsEquals(loc, lhs_im, rhs_im, op); if (op == TOKequal) return gIR->ir->CreateAnd(b1,b2,"tmp"); diff --git a/gen/complex.h b/gen/complex.h index d939a00d..04e84e08 100644 --- a/gen/complex.h +++ b/gen/complex.h @@ -14,6 +14,7 @@ DValue* DtoComplex(Loc& loc, Type* to, DValue* val); void DtoComplexSet(LLValue* c, LLValue* re, LLValue* im); +void DtoGetComplexParts(Loc& loc, Type* to, DValue* c, DValue*& re, DValue*& im); void DtoGetComplexParts(Loc& loc, Type* to, DValue* c, LLValue*& re, LLValue*& im); DValue* DtoComplexAdd(Loc& loc, Type* type, DValue* lhs, DValue* rhs); diff --git a/gen/llvmhelpers.h b/gen/llvmhelpers.h index f0d9fb5c..7d081683 100644 --- a/gen/llvmhelpers.h +++ b/gen/llvmhelpers.h @@ -121,6 +121,7 @@ DValue* DtoBinMul(Type* resulttype, DValue* lhs, DValue* rhs); DValue* DtoBinDiv(Type* resulttype, DValue* lhs, DValue* rhs); DValue* DtoBinRem(Type* resulttype, DValue* lhs, DValue* rhs); LLValue* DtoBinNumericEquals(Loc loc, DValue* lhs, DValue* rhs, TOK op); +LLValue* DtoBinFloatsEquals(Loc loc, DValue* lhs, DValue* rhs, TOK op); // target stuff void findDefaultTarget(); diff --git a/phobos b/phobos index 929ba442..a8106d9d 160000 --- a/phobos +++ b/phobos @@ -1 +1 @@ -Subproject commit 929ba4429446d114fe8d26addb3abf6791cb357e +Subproject commit a8106d9d48d7bf51ddfb312f334f2607b979aff1