mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-08-07 12:28:24 +00:00
Addresses many style issues with prior checkin (r169025)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@169043 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -252,6 +252,42 @@ Instruction *InstCombiner::visitMul(BinaryOperator &I) {
|
|||||||
return Changed ? &I : 0;
|
return Changed ? &I : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Detect pattern:
|
||||||
|
//
|
||||||
|
// log2(Y*0.5)
|
||||||
|
//
|
||||||
|
// And check for corresponding fast math flags
|
||||||
|
//
|
||||||
|
|
||||||
|
static void detectLog2OfHalf(Value *&Op, Value *&Y, IntrinsicInst *&Log2) {
|
||||||
|
if (Op->hasOneUse()) {
|
||||||
|
if (IntrinsicInst *II = dyn_cast<IntrinsicInst>(Op)) {
|
||||||
|
if (II->getIntrinsicID() == Intrinsic::log2 &&
|
||||||
|
II->hasUnsafeAlgebra()) {
|
||||||
|
Log2 = II;
|
||||||
|
Value *OpLog2Of = II->getArgOperand(0);
|
||||||
|
if (OpLog2Of->hasOneUse()) {
|
||||||
|
if (Instruction *I = dyn_cast<Instruction>(OpLog2Of)) {
|
||||||
|
if (I->getOpcode() == Instruction::FMul &&
|
||||||
|
I->hasUnsafeAlgebra()) {
|
||||||
|
ConstantFP *CFP = dyn_cast<ConstantFP>(I->getOperand(0));
|
||||||
|
if (CFP && CFP->isExactlyValue(0.5)) {
|
||||||
|
Y = I->getOperand(1);
|
||||||
|
} else {
|
||||||
|
CFP = dyn_cast<ConstantFP>(I->getOperand(1));
|
||||||
|
if (CFP && CFP->isExactlyValue(0.5)) {
|
||||||
|
Y = I->getOperand(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Instruction *InstCombiner::visitFMul(BinaryOperator &I) {
|
Instruction *InstCombiner::visitFMul(BinaryOperator &I) {
|
||||||
bool Changed = SimplifyAssociativeOrCommutative(I);
|
bool Changed = SimplifyAssociativeOrCommutative(I);
|
||||||
Value *Op0 = I.getOperand(0), *Op1 = I.getOperand(1);
|
Value *Op0 = I.getOperand(0), *Op1 = I.getOperand(1);
|
||||||
@@ -290,70 +326,20 @@ Instruction *InstCombiner::visitFMul(BinaryOperator &I) {
|
|||||||
Value *OpX = NULL;
|
Value *OpX = NULL;
|
||||||
Value *OpY = NULL;
|
Value *OpY = NULL;
|
||||||
IntrinsicInst *Log2;
|
IntrinsicInst *Log2;
|
||||||
if (Op0->hasOneUse()) {
|
detectLog2OfHalf(Op0, OpY, Log2);
|
||||||
if (IntrinsicInst *II = dyn_cast<IntrinsicInst>(Op0)) {
|
if (OpY) {
|
||||||
if (II->getIntrinsicID() == Intrinsic::log2 &&
|
OpX = Op1;
|
||||||
II->hasUnsafeAlgebra())
|
} else {
|
||||||
{
|
detectLog2OfHalf(Op1, OpY, Log2);
|
||||||
Log2 = II;
|
if (OpY) {
|
||||||
Value *OpLog2Of = II->getArgOperand(0);
|
OpX = Op0;
|
||||||
if (OpLog2Of->hasOneUse()) {
|
|
||||||
if (Instruction *I = dyn_cast<Instruction>(OpLog2Of)) {
|
|
||||||
if (I->getOpcode() == Instruction::FMul &&
|
|
||||||
I->hasUnsafeAlgebra())
|
|
||||||
{
|
|
||||||
ConstantFP *CFP = dyn_cast<ConstantFP>(I->getOperand(0));
|
|
||||||
if (CFP && CFP->isExactlyValue(0.5)) {
|
|
||||||
OpY = I->getOperand(1);
|
|
||||||
OpX = Op1;
|
|
||||||
} else {
|
|
||||||
CFP = dyn_cast<ConstantFP>(I->getOperand(1));
|
|
||||||
if (CFP && CFP->isExactlyValue(0.5)) {
|
|
||||||
OpY = I->getOperand(0);
|
|
||||||
OpX = Op1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (Op1->hasOneUse()) {
|
|
||||||
if (IntrinsicInst *II = dyn_cast<IntrinsicInst>(Op1)) {
|
|
||||||
if (II->getIntrinsicID() == Intrinsic::log2 &&
|
|
||||||
II->hasUnsafeAlgebra())
|
|
||||||
{
|
|
||||||
Log2 = II;
|
|
||||||
Value *OpLog2Of = II->getArgOperand(0);
|
|
||||||
if (OpLog2Of->hasOneUse()) {
|
|
||||||
if (Instruction *I = dyn_cast<Instruction>(OpLog2Of)) {
|
|
||||||
if (I->getOpcode() == Instruction::FMul &&
|
|
||||||
I->hasUnsafeAlgebra())
|
|
||||||
{
|
|
||||||
ConstantFP *CFP = dyn_cast<ConstantFP>(I->getOperand(0));
|
|
||||||
if (CFP && CFP->isExactlyValue(0.5)) {
|
|
||||||
OpY = I->getOperand(1);
|
|
||||||
OpX = Op0;
|
|
||||||
} else {
|
|
||||||
CFP = dyn_cast<ConstantFP>(I->getOperand(1));
|
|
||||||
if (CFP && CFP->isExactlyValue(0.5)) {
|
|
||||||
OpY = I->getOperand(0);
|
|
||||||
OpX = Op0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// if pattern detected emit alternate sequence
|
// if pattern detected emit alternate sequence
|
||||||
if (OpX && OpY) {
|
if (OpX && OpY) {
|
||||||
Log2->setArgOperand(0, OpY);
|
Log2->setArgOperand(0, OpY);
|
||||||
Value *FMulVal = Builder->CreateFMul(OpX, Log2);
|
Value *FMulVal = Builder->CreateFMul(OpX, Log2);
|
||||||
Instruction *FMul = dyn_cast<Instruction>(FMulVal);
|
Instruction *FMul = cast<Instruction>(FMulVal);
|
||||||
assert(FMul && "Must be instruction as Log2 is instruction");
|
|
||||||
FMul->copyFastMathFlags(Log2);
|
FMul->copyFastMathFlags(Log2);
|
||||||
Instruction *FSub = BinaryOperator::CreateFSub(FMulVal, OpX);
|
Instruction *FSub = BinaryOperator::CreateFSub(FMulVal, OpX);
|
||||||
FSub->copyFastMathFlags(Log2);
|
FSub->copyFastMathFlags(Log2);
|
||||||
|
Reference in New Issue
Block a user