mirror of
https://github.com/xomboverlord/ldc.git
synced 2026-01-11 18:33:14 +01:00
Made is and !is use the same numeric comparison as == and !=, fixes #328
Factored out common code from EqualExp and IdentityExp into DtoBinNumericEquals in binexp.cpp.
This commit is contained in:
@@ -5,6 +5,8 @@
|
||||
#include "gen/irstate.h"
|
||||
#include "gen/tollvm.h"
|
||||
#include "gen/dvalue.h"
|
||||
#include "gen/logger.h"
|
||||
#include "gen/complex.h"
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@@ -65,3 +67,34 @@ DValue* DtoBinRem(Type* targettype, DValue* lhs, DValue* rhs)
|
||||
res = gIR->ir->CreateURem(l, r, "tmp");
|
||||
return new DImValue( targettype, res );
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
LLValue* DtoBinNumericEquals(Loc loc, DValue* lhs, DValue* rhs, TOK op)
|
||||
{
|
||||
assert(op == TOKequal || op == TOKnotequal ||
|
||||
op == TOKidentity || op == TOKnotidentity);
|
||||
Type* t = lhs->getType()->toBasetype();
|
||||
assert(t->isfloating());
|
||||
Logger::println("numeric equality");
|
||||
|
||||
LLValue* lv = lhs->getRVal();
|
||||
LLValue* rv = rhs->getRVal();
|
||||
LLValue* res = 0;
|
||||
|
||||
if (t->iscomplex())
|
||||
{
|
||||
Logger::println("complex");
|
||||
res = DtoComplexEquals(loc, op, lhs, rhs);
|
||||
}
|
||||
else if (t->isfloating())
|
||||
{
|
||||
Logger::println("floating");
|
||||
res = (op == TOKidentity || op == TOKequal)
|
||||
? gIR->ir->CreateFCmpOEQ(lv,rv,"tmp")
|
||||
: gIR->ir->CreateFCmpUNE(lv,rv,"tmp");
|
||||
}
|
||||
|
||||
assert(res);
|
||||
return res;
|
||||
}
|
||||
|
||||
@@ -390,7 +390,7 @@ LLValue* DtoComplexEquals(Loc& loc, TOK op, DValue* lhs, DValue* rhs)
|
||||
|
||||
// select predicate
|
||||
llvm::FCmpInst::Predicate cmpop;
|
||||
if (op == TOKequal)
|
||||
if (op == TOKequal || op == TOKidentity)
|
||||
cmpop = llvm::FCmpInst::FCMP_OEQ;
|
||||
else
|
||||
cmpop = llvm::FCmpInst::FCMP_UNE;
|
||||
|
||||
@@ -119,6 +119,7 @@ DValue* DtoBinSub(DValue* lhs, DValue* rhs);
|
||||
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);
|
||||
|
||||
// target stuff
|
||||
void findDefaultTarget();
|
||||
|
||||
70
gen/toir.cpp
70
gen/toir.cpp
@@ -1437,6 +1437,8 @@ DValue* EqualExp::toElem(IRState* p)
|
||||
|
||||
DValue* l = e1->toElem(p);
|
||||
DValue* r = e2->toElem(p);
|
||||
LLValue* lv = l->getRVal();
|
||||
LLValue* rv = r->getRVal();
|
||||
|
||||
Type* t = e1->type->toBasetype();
|
||||
Type* e2t = e2->type->toBasetype();
|
||||
@@ -1461,8 +1463,6 @@ DValue* EqualExp::toElem(IRState* p)
|
||||
default:
|
||||
assert(0);
|
||||
}
|
||||
LLValue* lv = l->getRVal();
|
||||
LLValue* rv = r->getRVal();
|
||||
if (rv->getType() != lv->getType()) {
|
||||
rv = DtoBitCast(rv, lv->getType());
|
||||
}
|
||||
@@ -1473,27 +1473,9 @@ DValue* EqualExp::toElem(IRState* p)
|
||||
}
|
||||
eval = p->ir->CreateICmp(cmpop, lv, rv, "tmp");
|
||||
}
|
||||
else if (t->iscomplex())
|
||||
else if (t->isfloating()) // includes iscomplex
|
||||
{
|
||||
Logger::println("complex");
|
||||
eval = DtoComplexEquals(loc, op, l, r);
|
||||
}
|
||||
else if (t->isfloating())
|
||||
{
|
||||
Logger::println("floating");
|
||||
llvm::FCmpInst::Predicate cmpop;
|
||||
switch(op)
|
||||
{
|
||||
case TOKequal:
|
||||
cmpop = llvm::FCmpInst::FCMP_OEQ;
|
||||
break;
|
||||
case TOKnotequal:
|
||||
cmpop = llvm::FCmpInst::FCMP_UNE;
|
||||
break;
|
||||
default:
|
||||
assert(0);
|
||||
}
|
||||
eval = p->ir->CreateFCmp(cmpop, l->getRVal(), r->getRVal(), "tmp");
|
||||
eval = DtoBinNumericEquals(loc, l, r, op);
|
||||
}
|
||||
else if (t->ty == Tsarray || t->ty == Tarray)
|
||||
{
|
||||
@@ -2041,55 +2023,53 @@ DValue* IdentityExp::toElem(IRState* p)
|
||||
Logger::print("IdentityExp::toElem: %s @ %s\n", toChars(), type->toChars());
|
||||
LOG_SCOPE;
|
||||
|
||||
DValue* u = e1->toElem(p);
|
||||
DValue* v = e2->toElem(p);
|
||||
DValue* l = e1->toElem(p);
|
||||
DValue* r = e2->toElem(p);
|
||||
LLValue* lv = l->getRVal();
|
||||
LLValue* rv = r->getRVal();
|
||||
|
||||
Type* t1 = e1->type->toBasetype();
|
||||
|
||||
// handle dynarray specially
|
||||
if (t1->ty == Tarray)
|
||||
return new DImValue(type, DtoDynArrayIs(op,u,v));
|
||||
return new DImValue(type, DtoDynArrayIs(op,l,r));
|
||||
// also structs
|
||||
else if (t1->ty == Tstruct)
|
||||
return new DImValue(type, DtoStructEquals(op,u,v));
|
||||
return new DImValue(type, DtoStructEquals(op,l,r));
|
||||
|
||||
// FIXME this stuff isn't pretty
|
||||
LLValue* l = u->getRVal();
|
||||
LLValue* r = v->getRVal();
|
||||
LLValue* eval = 0;
|
||||
|
||||
if (t1->ty == Tdelegate) {
|
||||
if (v->isNull()) {
|
||||
r = NULL;
|
||||
if (r->isNull()) {
|
||||
rv = NULL;
|
||||
}
|
||||
else {
|
||||
assert(l->getType() == r->getType());
|
||||
assert(lv->getType() == rv->getType());
|
||||
}
|
||||
eval = DtoDelegateEquals(op,l,r);
|
||||
eval = DtoDelegateEquals(op,lv,rv);
|
||||
}
|
||||
else if (t1->isfloating())
|
||||
else if (t1->isfloating()) // includes iscomplex
|
||||
{
|
||||
eval = (op == TOKidentity)
|
||||
? p->ir->CreateFCmpOEQ(l,r,"tmp")
|
||||
: p->ir->CreateFCmpONE(l,r,"tmp");
|
||||
eval = DtoBinNumericEquals(loc, l, r, op);
|
||||
}
|
||||
else if (t1->ty == Tpointer || t1->ty == Tclass)
|
||||
{
|
||||
if (l->getType() != r->getType()) {
|
||||
if (v->isNull())
|
||||
r = llvm::ConstantPointerNull::get(isaPointer(l->getType()));
|
||||
if (lv->getType() != rv->getType()) {
|
||||
if (r->isNull())
|
||||
rv = llvm::ConstantPointerNull::get(isaPointer(lv->getType()));
|
||||
else
|
||||
r = DtoBitCast(r, l->getType());
|
||||
rv = DtoBitCast(rv, lv->getType());
|
||||
}
|
||||
eval = (op == TOKidentity)
|
||||
? p->ir->CreateICmpEQ(l,r,"tmp")
|
||||
: p->ir->CreateICmpNE(l,r,"tmp");
|
||||
? p->ir->CreateICmpEQ(lv,rv,"tmp")
|
||||
: p->ir->CreateICmpNE(lv,rv,"tmp");
|
||||
}
|
||||
else {
|
||||
assert(l->getType() == r->getType());
|
||||
assert(lv->getType() == rv->getType());
|
||||
eval = (op == TOKidentity)
|
||||
? p->ir->CreateICmpEQ(l,r,"tmp")
|
||||
: p->ir->CreateICmpNE(l,r,"tmp");
|
||||
? p->ir->CreateICmpEQ(lv,rv,"tmp")
|
||||
: p->ir->CreateICmpNE(lv,rv,"tmp");
|
||||
}
|
||||
return new DImValue(type, eval);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user