@@ -1322,8 +1322,8 @@ class ToElemVisitor : public Visitor {
1322
1322
auto &PGO = gIR ->funcGen ().pgo ;
1323
1323
PGO.setCurrentStmt (e);
1324
1324
1325
- DValue *l = toElem (e->e1 );
1326
- DValue *r = toElem (e->e2 );
1325
+ LLValue *l = DtoRVal (e->e1 );
1326
+ LLValue *r = DtoRVal (e->e2 );
1327
1327
1328
1328
Type *t = e->e1 ->type ->toBasetype ();
1329
1329
@@ -1334,16 +1334,14 @@ class ToElemVisitor : public Visitor {
1334
1334
tokToICmpPred (e->op , isLLVMUnsigned (t), &icmpPred, &eval);
1335
1335
1336
1336
if (!eval) {
1337
- LLValue *a = DtoRVal (l);
1338
- LLValue *b = DtoRVal (r);
1339
1337
IF_LOG {
1340
- Logger::cout () << " type 1: " << *a << ' \n ' ;
1341
- Logger::cout () << " type 2: " << *b << ' \n ' ;
1338
+ Logger::cout () << " type 1: " << *l << ' \n ' ;
1339
+ Logger::cout () << " type 2: " << *r << ' \n ' ;
1342
1340
}
1343
- if (a ->getType () != b ->getType ()) {
1344
- b = DtoBitCast (b, a ->getType ());
1341
+ if (l ->getType () != r ->getType ()) {
1342
+ r = DtoBitCast (r, l ->getType ());
1345
1343
}
1346
- eval = p->ir ->CreateICmp (icmpPred, a, b );
1344
+ eval = p->ir ->CreateICmp (icmpPred, l, r );
1347
1345
}
1348
1346
} else if (t->isfloating ()) {
1349
1347
llvm::FCmpInst::Predicate cmpop;
@@ -1364,7 +1362,7 @@ class ToElemVisitor : public Visitor {
1364
1362
default :
1365
1363
llvm_unreachable (" Unsupported floating point comparison operator." );
1366
1364
}
1367
- eval = p->ir ->CreateFCmp (cmpop, DtoRVal (l), DtoRVal (r) );
1365
+ eval = p->ir ->CreateFCmp (cmpop, l, r );
1368
1366
} else if (t->ty == TY::Taarray) {
1369
1367
eval = LLConstantInt::getFalse (gIR ->context ());
1370
1368
} else if (t->ty == TY::Tdelegate) {
@@ -1374,23 +1372,21 @@ class ToElemVisitor : public Visitor {
1374
1372
if (!eval) {
1375
1373
// First compare the function pointers, then the context ones. This is
1376
1374
// what DMD does.
1377
- llvm::Value *lhs = DtoRVal (l);
1378
- llvm::Value *rhs = DtoRVal (r);
1379
1375
1380
1376
llvm::BasicBlock *fptreq = p->insertBB (" fptreq" );
1381
1377
llvm::BasicBlock *fptrneq = p->insertBBAfter (fptreq, " fptrneq" );
1382
1378
llvm::BasicBlock *dgcmpend = p->insertBBAfter (fptrneq, " dgcmpend" );
1383
1379
1384
- llvm::Value *lfptr = p->ir ->CreateExtractValue (lhs , 1 , " .lfptr" );
1385
- llvm::Value *rfptr = p->ir ->CreateExtractValue (rhs , 1 , " .rfptr" );
1380
+ llvm::Value *lfptr = p->ir ->CreateExtractValue (l , 1 , " .lfptr" );
1381
+ llvm::Value *rfptr = p->ir ->CreateExtractValue (r , 1 , " .rfptr" );
1386
1382
1387
1383
llvm::Value *fptreqcmp = p->ir ->CreateICmp (llvm::ICmpInst::ICMP_EQ,
1388
1384
lfptr, rfptr, " .fptreqcmp" );
1389
1385
llvm::BranchInst::Create (fptreq, fptrneq, fptreqcmp, p->scopebb ());
1390
1386
1391
1387
p->ir ->SetInsertPoint (fptreq);
1392
- llvm::Value *lctx = p->ir ->CreateExtractValue (lhs , 0 , " .lctx" );
1393
- llvm::Value *rctx = p->ir ->CreateExtractValue (rhs , 0 , " .rctx" );
1388
+ llvm::Value *lctx = p->ir ->CreateExtractValue (l , 0 , " .lctx" );
1389
+ llvm::Value *rctx = p->ir ->CreateExtractValue (r , 0 , " .rctx" );
1394
1390
llvm::Value *ctxcmp =
1395
1391
p->ir ->CreateICmp (icmpPred, lctx, rctx, " .ctxcmp" );
1396
1392
llvm::BranchInst::Create (dgcmpend, p->scopebb ());
@@ -1423,10 +1419,10 @@ class ToElemVisitor : public Visitor {
1423
1419
auto &PGO = gIR ->funcGen ().pgo ;
1424
1420
PGO.setCurrentStmt (e);
1425
1421
1426
- DValue *l = toElem ( e->e1 ) ;
1427
- DValue *r = toElem ( e->e2 ) ;
1422
+ Expression *l = e->e1 ;
1423
+ Expression *r = e->e2 ;
1428
1424
1429
- Type *t = e-> e1 ->type ->toBasetype ();
1425
+ Type *t = l ->type ->toBasetype ();
1430
1426
1431
1427
LLValue *eval = nullptr ;
1432
1428
@@ -1457,20 +1453,22 @@ class ToElemVisitor : public Visitor {
1457
1453
}
1458
1454
eval = p->ir ->CreateICmp (cmpop, lv, rv);
1459
1455
} else if (t->isfloating ()) { // includes iscomplex
1460
- eval = DtoBinNumericEquals (e->loc , l, r, e->op );
1456
+ eval = DtoBinNumericEquals (e->loc , toElem (l)->getRVal (),
1457
+ toElem (r)->getRVal (), e->op );
1461
1458
} else if (t->ty == TY::Tsarray || t->ty == TY::Tarray) {
1462
1459
Logger::println (" static or dynamic array" );
1463
- eval = DtoArrayEquals (e->loc , e->op , l, r );
1460
+ eval = DtoArrayEquals (e->loc , e->op , toElem (l), toElem (r) );
1464
1461
} else if (t->ty == TY::Taarray) {
1465
1462
Logger::println (" associative array" );
1466
- eval = DtoAAEquals (e->loc , e->op , l, r);
1463
+ eval = DtoAAEquals (e->loc , e->op , toElem (l)->getRVal (),
1464
+ toElem (r)->getRVal ());
1467
1465
} else if (t->ty == TY::Tdelegate) {
1468
1466
Logger::println (" delegate" );
1469
1467
eval = DtoDelegateEquals (e->op , DtoRVal (l), DtoRVal (r));
1470
1468
} else if (t->ty == TY::Tstruct) {
1471
1469
Logger::println (" struct" );
1472
1470
// when this is reached it means there is no opEquals overload.
1473
- eval = DtoStructEquals (e->op , l, r );
1471
+ eval = DtoStructEquals (e->op , toElem (l), toElem (r) );
1474
1472
} else {
1475
1473
llvm_unreachable (" Unsupported EqualExp type." );
1476
1474
}
@@ -2028,45 +2026,35 @@ class ToElemVisitor : public Visitor {
2028
2026
e->type ->toChars ());
2029
2027
LOG_SCOPE;
2030
2028
2031
- DValue *l = toElem (e->e1 );
2032
- DValue *r = toElem (e->e2 );
2033
-
2034
- Type *t1 = e->e1 ->type ->toBasetype ();
2029
+ Expression *l = e->e1 ;
2030
+ Expression *r = e->e2 ;
2035
2031
2036
- // handle dynarray specially
2037
- if (t1->ty == TY::Tarray) {
2038
- result = zextBool (DtoDynArrayIs (e->op , l, r), e->type );
2039
- return ;
2040
- }
2041
- // also structs
2042
- if (t1->ty == TY::Tstruct) {
2043
- result = zextBool (DtoStructEquals (e->op , l, r), e->type );
2044
- return ;
2045
- }
2032
+ Type *t1 = l->type ->toBasetype ();
2046
2033
2047
- // FIXME this stuff isn't pretty
2048
2034
LLValue *eval = nullptr ;
2049
2035
2050
- if (t1->ty == TY::Tdelegate) {
2036
+ if (t1->ty == TY::Tarray) {
2037
+ eval = DtoDynArrayIs (e->op , toElem (l), toElem (r));
2038
+ } else if (t1->ty == TY::Tstruct) {
2039
+ eval = DtoStructEquals (e->op , toElem (l), toElem (r));
2040
+ } else if (t1->ty == TY::Tdelegate) {
2051
2041
LLValue *lv = DtoRVal (l);
2042
+ DValue *rhs = toElem (r);
2043
+
2052
2044
LLValue *rv = nullptr ;
2053
- if (!r ->isNull ()) {
2054
- rv = DtoRVal (r );
2045
+ if (!rhs ->isNull ()) {
2046
+ rv = DtoRVal (rhs );
2055
2047
assert (lv->getType () == rv->getType ());
2056
2048
}
2049
+
2057
2050
eval = DtoDelegateEquals (e->op , lv, rv);
2058
2051
} else if (t1->isfloating ()) { // includes iscomplex
2059
- eval = DtoBinNumericEquals (e->loc , l, r, e->op );
2052
+ eval = DtoBinNumericEquals (e->loc , toElem (l)->getRVal (),
2053
+ toElem (r)->getRVal (), e->op );
2060
2054
} else if (t1->ty == TY::Tpointer || t1->ty == TY::Tclass) {
2061
2055
LLValue *lv = DtoRVal (l);
2062
2056
LLValue *rv = DtoRVal (r);
2063
- if (lv->getType () != rv->getType ()) {
2064
- if (r->isNull ()) {
2065
- rv = llvm::ConstantPointerNull::get (isaPointer (lv));
2066
- } else {
2067
- rv = DtoBitCast (rv, lv->getType ());
2068
- }
2069
- }
2057
+ rv = DtoBitCast (rv, lv->getType ());
2070
2058
eval = (e->op == EXP::identity) ? p->ir ->CreateICmpEQ (lv, rv)
2071
2059
: p->ir ->CreateICmpNE (lv, rv);
2072
2060
} else if (t1->ty == TY::Tsarray) {
@@ -2086,6 +2074,7 @@ class ToElemVisitor : public Visitor {
2086
2074
: EXP::notEqual);
2087
2075
}
2088
2076
}
2077
+
2089
2078
result = zextBool (eval, e->type );
2090
2079
}
2091
2080
0 commit comments