mirror of
https://github.com/xomboverlord/ldc.git
synced 2026-10-22 02:37:26 +02:00
No need for temporary alloca's here, use a phi node instead.
This commit is contained in:
+36
-17
@@ -1828,10 +1828,6 @@ DValue* AndAndExp::toElem(IRState* p)
|
|||||||
Logger::print("AndAndExp::toElem: %s @ %s\n", toChars(), type->toChars());
|
Logger::print("AndAndExp::toElem: %s @ %s\n", toChars(), type->toChars());
|
||||||
LOG_SCOPE;
|
LOG_SCOPE;
|
||||||
|
|
||||||
// allocate a temporary for the final result. failed to come up with a better way :/
|
|
||||||
LLValue* resval = 0;
|
|
||||||
resval = DtoAlloca(LLType::Int1Ty,"andandtmp");
|
|
||||||
|
|
||||||
DValue* u = e1->toElem(p);
|
DValue* u = e1->toElem(p);
|
||||||
|
|
||||||
llvm::BasicBlock* oldend = p->scopeend();
|
llvm::BasicBlock* oldend = p->scopeend();
|
||||||
@@ -1839,23 +1835,36 @@ DValue* AndAndExp::toElem(IRState* p)
|
|||||||
llvm::BasicBlock* andandend = llvm::BasicBlock::Create("andandend", gIR->topfunc(), oldend);
|
llvm::BasicBlock* andandend = llvm::BasicBlock::Create("andandend", gIR->topfunc(), oldend);
|
||||||
|
|
||||||
LLValue* ubool = DtoCast(loc, u, Type::tbool)->getRVal();
|
LLValue* ubool = DtoCast(loc, u, Type::tbool)->getRVal();
|
||||||
DtoStore(ubool,resval);
|
|
||||||
|
llvm::BasicBlock* oldblock = p->scopebb();
|
||||||
llvm::BranchInst::Create(andand,andandend,ubool,p->scopebb());
|
llvm::BranchInst::Create(andand,andandend,ubool,p->scopebb());
|
||||||
|
|
||||||
p->scope() = IRScope(andand, andandend);
|
p->scope() = IRScope(andand, andandend);
|
||||||
DValue* v = e2->toElem(p);
|
DValue* v = e2->toElem(p);
|
||||||
|
|
||||||
|
LLValue* vbool = 0;
|
||||||
if (!v->isFunc() && v->getType() != Type::tvoid)
|
if (!v->isFunc() && v->getType() != Type::tvoid)
|
||||||
{
|
{
|
||||||
LLValue* vbool = DtoCast(loc, v, Type::tbool)->getRVal();
|
vbool = DtoCast(loc, v, Type::tbool)->getRVal();
|
||||||
LLValue* uandvbool = llvm::BinaryOperator::Create(llvm::BinaryOperator::And, ubool, vbool,"tmp",p->scopebb());
|
|
||||||
DtoStore(uandvbool,resval);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
llvm::BasicBlock* newblock = p->scopebb();
|
||||||
llvm::BranchInst::Create(andandend,p->scopebb());
|
llvm::BranchInst::Create(andandend,p->scopebb());
|
||||||
p->scope() = IRScope(andandend, oldend);
|
p->scope() = IRScope(andandend, oldend);
|
||||||
|
|
||||||
resval = DtoLoad(resval);
|
LLValue* resval = 0;
|
||||||
|
if (ubool == vbool || !vbool) {
|
||||||
|
// No need to create a PHI node.
|
||||||
|
resval = ubool;
|
||||||
|
} else {
|
||||||
|
llvm::PHINode* phi = p->ir->CreatePHI(LLType::Int1Ty, "andandval");
|
||||||
|
// If we jumped over evaluation of the right-hand side,
|
||||||
|
// the result is false. Otherwise it's the value of the right-hand side.
|
||||||
|
phi->addIncoming(LLConstantInt::getFalse(), oldblock);
|
||||||
|
phi->addIncoming(vbool, newblock);
|
||||||
|
resval = phi;
|
||||||
|
}
|
||||||
|
|
||||||
return new DImValue(type, resval);
|
return new DImValue(type, resval);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1866,10 +1875,6 @@ DValue* OrOrExp::toElem(IRState* p)
|
|||||||
Logger::print("OrOrExp::toElem: %s @ %s\n", toChars(), type->toChars());
|
Logger::print("OrOrExp::toElem: %s @ %s\n", toChars(), type->toChars());
|
||||||
LOG_SCOPE;
|
LOG_SCOPE;
|
||||||
|
|
||||||
// allocate a temporary for the final result. failed to come up with a better way :/
|
|
||||||
LLValue* resval = 0;
|
|
||||||
resval = DtoAlloca(LLType::Int1Ty,"orortmp");
|
|
||||||
|
|
||||||
DValue* u = e1->toElem(p);
|
DValue* u = e1->toElem(p);
|
||||||
|
|
||||||
llvm::BasicBlock* oldend = p->scopeend();
|
llvm::BasicBlock* oldend = p->scopeend();
|
||||||
@@ -1877,22 +1882,36 @@ DValue* OrOrExp::toElem(IRState* p)
|
|||||||
llvm::BasicBlock* ororend = llvm::BasicBlock::Create("ororend", gIR->topfunc(), oldend);
|
llvm::BasicBlock* ororend = llvm::BasicBlock::Create("ororend", gIR->topfunc(), oldend);
|
||||||
|
|
||||||
LLValue* ubool = DtoCast(loc, u, Type::tbool)->getRVal();
|
LLValue* ubool = DtoCast(loc, u, Type::tbool)->getRVal();
|
||||||
DtoStore(ubool,resval);
|
|
||||||
|
llvm::BasicBlock* oldblock = p->scopebb();
|
||||||
llvm::BranchInst::Create(ororend,oror,ubool,p->scopebb());
|
llvm::BranchInst::Create(ororend,oror,ubool,p->scopebb());
|
||||||
|
|
||||||
p->scope() = IRScope(oror, ororend);
|
p->scope() = IRScope(oror, ororend);
|
||||||
DValue* v = e2->toElem(p);
|
DValue* v = e2->toElem(p);
|
||||||
|
|
||||||
|
LLValue* vbool = 0;
|
||||||
if (!v->isFunc() && v->getType() != Type::tvoid)
|
if (!v->isFunc() && v->getType() != Type::tvoid)
|
||||||
{
|
{
|
||||||
LLValue* vbool = DtoCast(loc, v, Type::tbool)->getRVal();
|
vbool = DtoCast(loc, v, Type::tbool)->getRVal();
|
||||||
DtoStore(vbool,resval);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
llvm::BasicBlock* newblock = p->scopebb();
|
||||||
llvm::BranchInst::Create(ororend,p->scopebb());
|
llvm::BranchInst::Create(ororend,p->scopebb());
|
||||||
p->scope() = IRScope(ororend, oldend);
|
p->scope() = IRScope(ororend, oldend);
|
||||||
|
|
||||||
resval = DtoLoad(resval);
|
LLValue* resval = 0;
|
||||||
|
if (ubool == vbool || !vbool) {
|
||||||
|
// No need to create a PHI node.
|
||||||
|
resval = ubool;
|
||||||
|
} else {
|
||||||
|
llvm::PHINode* phi = p->ir->CreatePHI(LLType::Int1Ty, "ororval");
|
||||||
|
// If we jumped over evaluation of the right-hand side,
|
||||||
|
// the result is true. Otherwise, it's the value of the right-hand side.
|
||||||
|
phi->addIncoming(LLConstantInt::getTrue(), oldblock);
|
||||||
|
phi->addIncoming(vbool, newblock);
|
||||||
|
resval = phi;
|
||||||
|
}
|
||||||
|
|
||||||
return new DImValue(type, resval);
|
return new DImValue(type, resval);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user