|
|
@ -322,8 +322,12 @@ bool SplitComparesTransform::simplifyFPCompares(Module &M) {
|
|
|
|
* block bb it is now at the position where the old FcmpInst was */
|
|
|
|
* block bb it is now at the position where the old FcmpInst was */
|
|
|
|
Instruction *fcmp_np;
|
|
|
|
Instruction *fcmp_np;
|
|
|
|
fcmp_np = CmpInst::Create(Instruction::FCmp, new_pred, op0, op1);
|
|
|
|
fcmp_np = CmpInst::Create(Instruction::FCmp, new_pred, op0, op1);
|
|
|
|
|
|
|
|
#if LLVM_MAJOR >= 16
|
|
|
|
|
|
|
|
fcmp_np->insertInto(bb, BasicBlock::iterator(bb->getTerminator()));
|
|
|
|
|
|
|
|
#else
|
|
|
|
bb->getInstList().insert(BasicBlock::iterator(bb->getTerminator()),
|
|
|
|
bb->getInstList().insert(BasicBlock::iterator(bb->getTerminator()),
|
|
|
|
fcmp_np);
|
|
|
|
fcmp_np);
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
/* create a new basic block which holds the new EQ fcmp */
|
|
|
|
/* create a new basic block which holds the new EQ fcmp */
|
|
|
|
Instruction *fcmp_eq;
|
|
|
|
Instruction *fcmp_eq;
|
|
|
@ -331,7 +335,11 @@ bool SplitComparesTransform::simplifyFPCompares(Module &M) {
|
|
|
|
BasicBlock *middle_bb =
|
|
|
|
BasicBlock *middle_bb =
|
|
|
|
BasicBlock::Create(C, "injected", end_bb->getParent(), end_bb);
|
|
|
|
BasicBlock::Create(C, "injected", end_bb->getParent(), end_bb);
|
|
|
|
fcmp_eq = CmpInst::Create(Instruction::FCmp, CmpInst::FCMP_OEQ, op0, op1);
|
|
|
|
fcmp_eq = CmpInst::Create(Instruction::FCmp, CmpInst::FCMP_OEQ, op0, op1);
|
|
|
|
|
|
|
|
#if LLVM_MAJOR >= 16
|
|
|
|
|
|
|
|
fcmp_eq->insertInto(middle_bb, middle_bb->end());
|
|
|
|
|
|
|
|
#else
|
|
|
|
middle_bb->getInstList().push_back(fcmp_eq);
|
|
|
|
middle_bb->getInstList().push_back(fcmp_eq);
|
|
|
|
|
|
|
|
#endif
|
|
|
|
/* add an unconditional branch to the end of middle_bb with destination
|
|
|
|
/* add an unconditional branch to the end of middle_bb with destination
|
|
|
|
* end_bb */
|
|
|
|
* end_bb */
|
|
|
|
BranchInst::Create(end_bb, middle_bb);
|
|
|
|
BranchInst::Create(end_bb, middle_bb);
|
|
|
@ -352,7 +360,11 @@ bool SplitComparesTransform::simplifyFPCompares(Module &M) {
|
|
|
|
PN->addIncoming(ConstantInt::get(Int1Ty, 1), bb);
|
|
|
|
PN->addIncoming(ConstantInt::get(Int1Ty, 1), bb);
|
|
|
|
/* replace the old FcmpInst with our new and shiny PHI inst */
|
|
|
|
/* replace the old FcmpInst with our new and shiny PHI inst */
|
|
|
|
BasicBlock::iterator ii(FcmpInst);
|
|
|
|
BasicBlock::iterator ii(FcmpInst);
|
|
|
|
|
|
|
|
#if LLVM_MAJOR >= 16
|
|
|
|
|
|
|
|
ReplaceInstWithInst(FcmpInst->getParent(), ii, PN);
|
|
|
|
|
|
|
|
#else
|
|
|
|
ReplaceInstWithInst(FcmpInst->getParent()->getInstList(), ii, PN);
|
|
|
|
ReplaceInstWithInst(FcmpInst->getParent()->getInstList(), ii, PN);
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -409,7 +421,11 @@ bool SplitComparesTransform::simplifyOrEqualsCompare(CmpInst *IcmpInst,
|
|
|
|
/* create the ICMP instruction with new_pred and add it to the old basic
|
|
|
|
/* create the ICMP instruction with new_pred and add it to the old basic
|
|
|
|
* block bb it is now at the position where the old IcmpInst was */
|
|
|
|
* block bb it is now at the position where the old IcmpInst was */
|
|
|
|
CmpInst *icmp_np = CmpInst::Create(Instruction::ICmp, new_pred, op0, op1);
|
|
|
|
CmpInst *icmp_np = CmpInst::Create(Instruction::ICmp, new_pred, op0, op1);
|
|
|
|
|
|
|
|
#if LLVM_MAJOR >= 16
|
|
|
|
|
|
|
|
icmp_np->insertInto(bb, BasicBlock::iterator(bb->getTerminator()));
|
|
|
|
|
|
|
|
#else
|
|
|
|
bb->getInstList().insert(BasicBlock::iterator(bb->getTerminator()), icmp_np);
|
|
|
|
bb->getInstList().insert(BasicBlock::iterator(bb->getTerminator()), icmp_np);
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
/* create a new basic block which holds the new EQ icmp */
|
|
|
|
/* create a new basic block which holds the new EQ icmp */
|
|
|
|
CmpInst *icmp_eq;
|
|
|
|
CmpInst *icmp_eq;
|
|
|
@ -417,7 +433,11 @@ bool SplitComparesTransform::simplifyOrEqualsCompare(CmpInst *IcmpInst,
|
|
|
|
BasicBlock *middle_bb =
|
|
|
|
BasicBlock *middle_bb =
|
|
|
|
BasicBlock::Create(C, "injected", end_bb->getParent(), end_bb);
|
|
|
|
BasicBlock::Create(C, "injected", end_bb->getParent(), end_bb);
|
|
|
|
icmp_eq = CmpInst::Create(Instruction::ICmp, CmpInst::ICMP_EQ, op0, op1);
|
|
|
|
icmp_eq = CmpInst::Create(Instruction::ICmp, CmpInst::ICMP_EQ, op0, op1);
|
|
|
|
|
|
|
|
#if LLVM_MAJOR >= 16
|
|
|
|
|
|
|
|
icmp_eq->insertInto(middle_bb, middle_bb->end());
|
|
|
|
|
|
|
|
#else
|
|
|
|
middle_bb->getInstList().push_back(icmp_eq);
|
|
|
|
middle_bb->getInstList().push_back(icmp_eq);
|
|
|
|
|
|
|
|
#endif
|
|
|
|
/* add an unconditional branch to the end of middle_bb with destination
|
|
|
|
/* add an unconditional branch to the end of middle_bb with destination
|
|
|
|
* end_bb */
|
|
|
|
* end_bb */
|
|
|
|
BranchInst::Create(end_bb, middle_bb);
|
|
|
|
BranchInst::Create(end_bb, middle_bb);
|
|
|
@ -438,7 +458,11 @@ bool SplitComparesTransform::simplifyOrEqualsCompare(CmpInst *IcmpInst,
|
|
|
|
PN->addIncoming(ConstantInt::get(Int1Ty, 1), bb);
|
|
|
|
PN->addIncoming(ConstantInt::get(Int1Ty, 1), bb);
|
|
|
|
/* replace the old IcmpInst with our new and shiny PHI inst */
|
|
|
|
/* replace the old IcmpInst with our new and shiny PHI inst */
|
|
|
|
BasicBlock::iterator ii(IcmpInst);
|
|
|
|
BasicBlock::iterator ii(IcmpInst);
|
|
|
|
|
|
|
|
#if LLVM_MAJOR >= 16
|
|
|
|
|
|
|
|
ReplaceInstWithInst(IcmpInst->getParent(), ii, PN);
|
|
|
|
|
|
|
|
#else
|
|
|
|
ReplaceInstWithInst(IcmpInst->getParent()->getInstList(), ii, PN);
|
|
|
|
ReplaceInstWithInst(IcmpInst->getParent()->getInstList(), ii, PN);
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
worklist.push_back(icmp_np);
|
|
|
|
worklist.push_back(icmp_np);
|
|
|
|
worklist.push_back(icmp_eq);
|
|
|
|
worklist.push_back(icmp_eq);
|
|
|
@ -518,7 +542,11 @@ bool SplitComparesTransform::simplifySignedCompare(CmpInst *IcmpInst, Module &M,
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#if LLVM_MAJOR >= 16
|
|
|
|
|
|
|
|
icmp_inv_sig_cmp->insertInto(sign_bb, sign_bb->end());
|
|
|
|
|
|
|
|
#else
|
|
|
|
sign_bb->getInstList().push_back(icmp_inv_sig_cmp);
|
|
|
|
sign_bb->getInstList().push_back(icmp_inv_sig_cmp);
|
|
|
|
|
|
|
|
#endif
|
|
|
|
BranchInst::Create(end_bb, sign_bb);
|
|
|
|
BranchInst::Create(end_bb, sign_bb);
|
|
|
|
|
|
|
|
|
|
|
|
/* create a new bb which is executed if signedness is equal */
|
|
|
|
/* create a new bb which is executed if signedness is equal */
|
|
|
@ -528,7 +556,11 @@ bool SplitComparesTransform::simplifySignedCompare(CmpInst *IcmpInst, Module &M,
|
|
|
|
/* we can do a normal unsigned compare now */
|
|
|
|
/* we can do a normal unsigned compare now */
|
|
|
|
icmp_usign_cmp = CmpInst::Create(Instruction::ICmp, new_pred, op0, op1);
|
|
|
|
icmp_usign_cmp = CmpInst::Create(Instruction::ICmp, new_pred, op0, op1);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#if LLVM_MAJOR >= 16
|
|
|
|
|
|
|
|
icmp_usign_cmp->insertInto(middle_bb, middle_bb->end());
|
|
|
|
|
|
|
|
#else
|
|
|
|
middle_bb->getInstList().push_back(icmp_usign_cmp);
|
|
|
|
middle_bb->getInstList().push_back(icmp_usign_cmp);
|
|
|
|
|
|
|
|
#endif
|
|
|
|
BranchInst::Create(end_bb, middle_bb);
|
|
|
|
BranchInst::Create(end_bb, middle_bb);
|
|
|
|
|
|
|
|
|
|
|
|
auto term = bb->getTerminator();
|
|
|
|
auto term = bb->getTerminator();
|
|
|
@ -543,7 +575,11 @@ bool SplitComparesTransform::simplifySignedCompare(CmpInst *IcmpInst, Module &M,
|
|
|
|
PN->addIncoming(icmp_inv_sig_cmp, sign_bb);
|
|
|
|
PN->addIncoming(icmp_inv_sig_cmp, sign_bb);
|
|
|
|
|
|
|
|
|
|
|
|
BasicBlock::iterator ii(IcmpInst);
|
|
|
|
BasicBlock::iterator ii(IcmpInst);
|
|
|
|
|
|
|
|
#if LLVM_MAJOR >= 16
|
|
|
|
|
|
|
|
ReplaceInstWithInst(IcmpInst->getParent(), ii, PN);
|
|
|
|
|
|
|
|
#else
|
|
|
|
ReplaceInstWithInst(IcmpInst->getParent()->getInstList(), ii, PN);
|
|
|
|
ReplaceInstWithInst(IcmpInst->getParent()->getInstList(), ii, PN);
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
// save for later
|
|
|
|
// save for later
|
|
|
|
worklist.push_back(icmp_usign_cmp);
|
|
|
|
worklist.push_back(icmp_usign_cmp);
|
|
|
@ -717,7 +753,11 @@ bool SplitComparesTransform::splitCompare(CmpInst *cmp_inst, Module &M,
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#if LLVM_MAJOR >= 16
|
|
|
|
|
|
|
|
icmp_inv_cmp->insertInto(inv_cmp_bb, inv_cmp_bb->end());
|
|
|
|
|
|
|
|
#else
|
|
|
|
inv_cmp_bb->getInstList().push_back(icmp_inv_cmp);
|
|
|
|
inv_cmp_bb->getInstList().push_back(icmp_inv_cmp);
|
|
|
|
|
|
|
|
#endif
|
|
|
|
worklist.push_back(icmp_inv_cmp);
|
|
|
|
worklist.push_back(icmp_inv_cmp);
|
|
|
|
|
|
|
|
|
|
|
|
auto term = bb->getTerminator();
|
|
|
|
auto term = bb->getTerminator();
|
|
|
@ -728,12 +768,18 @@ bool SplitComparesTransform::splitCompare(CmpInst *cmp_inst, Module &M,
|
|
|
|
BasicBlock *cmp_low_bb =
|
|
|
|
BasicBlock *cmp_low_bb =
|
|
|
|
BasicBlock::Create(C, "" /*"injected"*/, end_bb->getParent(), end_bb);
|
|
|
|
BasicBlock::Create(C, "" /*"injected"*/, end_bb->getParent(), end_bb);
|
|
|
|
op0_low = new TruncInst(op0, NewIntType);
|
|
|
|
op0_low = new TruncInst(op0, NewIntType);
|
|
|
|
cmp_low_bb->getInstList().push_back(op0_low);
|
|
|
|
|
|
|
|
op1_low = new TruncInst(op1, NewIntType);
|
|
|
|
op1_low = new TruncInst(op1, NewIntType);
|
|
|
|
cmp_low_bb->getInstList().push_back(op1_low);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
icmp_low = CmpInst::Create(Instruction::ICmp, pred, op0_low, op1_low);
|
|
|
|
icmp_low = CmpInst::Create(Instruction::ICmp, pred, op0_low, op1_low);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#if LLVM_MAJOR >= 16
|
|
|
|
|
|
|
|
op0_low->insertInto(cmp_low_bb, cmp_low_bb->end());
|
|
|
|
|
|
|
|
op1_low->insertInto(cmp_low_bb, cmp_low_bb->end());
|
|
|
|
|
|
|
|
icmp_low->insertInto(cmp_low_bb, cmp_low_bb->end());
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
cmp_low_bb->getInstList().push_back(op0_low);
|
|
|
|
|
|
|
|
cmp_low_bb->getInstList().push_back(op1_low);
|
|
|
|
cmp_low_bb->getInstList().push_back(icmp_low);
|
|
|
|
cmp_low_bb->getInstList().push_back(icmp_low);
|
|
|
|
|
|
|
|
#endif
|
|
|
|
BranchInst::Create(end_bb, cmp_low_bb);
|
|
|
|
BranchInst::Create(end_bb, cmp_low_bb);
|
|
|
|
|
|
|
|
|
|
|
|
BranchInst::Create(end_bb, cmp_low_bb, icmp_inv_cmp, inv_cmp_bb);
|
|
|
|
BranchInst::Create(end_bb, cmp_low_bb, icmp_inv_cmp, inv_cmp_bb);
|
|
|
@ -754,7 +800,11 @@ bool SplitComparesTransform::splitCompare(CmpInst *cmp_inst, Module &M,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
BasicBlock::iterator ii(cmp_inst);
|
|
|
|
BasicBlock::iterator ii(cmp_inst);
|
|
|
|
|
|
|
|
#if LLVM_MAJOR >= 16
|
|
|
|
|
|
|
|
ReplaceInstWithInst(cmp_inst->getParent(), ii, PN);
|
|
|
|
|
|
|
|
#else
|
|
|
|
ReplaceInstWithInst(cmp_inst->getParent()->getInstList(), ii, PN);
|
|
|
|
ReplaceInstWithInst(cmp_inst->getParent()->getInstList(), ii, PN);
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
// We split the comparison into low and high. If this isn't our target
|
|
|
|
// We split the comparison into low and high. If this isn't our target
|
|
|
|
// bitwidth we recursively split the low and high parts again until we have
|
|
|
|
// bitwidth we recursively split the low and high parts again until we have
|
|
|
@ -999,13 +1049,21 @@ size_t SplitComparesTransform::splitFPCompares(Module &M) {
|
|
|
|
Instruction *bpre_op0, *bpre_op1;
|
|
|
|
Instruction *bpre_op0, *bpre_op1;
|
|
|
|
bpre_op0 = CastInst::Create(Instruction::BitCast, op0,
|
|
|
|
bpre_op0 = CastInst::Create(Instruction::BitCast, op0,
|
|
|
|
IntegerType::get(C, op_size));
|
|
|
|
IntegerType::get(C, op_size));
|
|
|
|
|
|
|
|
#if LLVM_MAJOR >= 16
|
|
|
|
|
|
|
|
bpre_op0->insertInto(bb, BasicBlock::iterator(bb->getTerminator()));
|
|
|
|
|
|
|
|
#else
|
|
|
|
bb->getInstList().insert(BasicBlock::iterator(bb->getTerminator()),
|
|
|
|
bb->getInstList().insert(BasicBlock::iterator(bb->getTerminator()),
|
|
|
|
bpre_op0);
|
|
|
|
bpre_op0);
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
bpre_op1 = CastInst::Create(Instruction::BitCast, op1,
|
|
|
|
bpre_op1 = CastInst::Create(Instruction::BitCast, op1,
|
|
|
|
IntegerType::get(C, op_size));
|
|
|
|
IntegerType::get(C, op_size));
|
|
|
|
|
|
|
|
#if LLVM_MAJOR >= 16
|
|
|
|
|
|
|
|
bpre_op1->insertInto(bb, BasicBlock::iterator(bb->getTerminator()));
|
|
|
|
|
|
|
|
#else
|
|
|
|
bb->getInstList().insert(BasicBlock::iterator(bb->getTerminator()),
|
|
|
|
bb->getInstList().insert(BasicBlock::iterator(bb->getTerminator()),
|
|
|
|
bpre_op1);
|
|
|
|
bpre_op1);
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
/* Check if any operand is NaN.
|
|
|
|
/* Check if any operand is NaN.
|
|
|
|
* If so, all comparisons except unequal (which yields true) yield false */
|
|
|
|
* If so, all comparisons except unequal (which yields true) yield false */
|
|
|
@ -1025,34 +1083,42 @@ size_t SplitComparesTransform::splitFPCompares(Module &M) {
|
|
|
|
Instruction *nan_op0, *nan_op1;
|
|
|
|
Instruction *nan_op0, *nan_op1;
|
|
|
|
nan_op0 = BinaryOperator::Create(Instruction::Shl, bpre_op0,
|
|
|
|
nan_op0 = BinaryOperator::Create(Instruction::Shl, bpre_op0,
|
|
|
|
ConstantInt::get(bpre_op0->getType(), 1));
|
|
|
|
ConstantInt::get(bpre_op0->getType(), 1));
|
|
|
|
bb->getInstList().insert(BasicBlock::iterator(bb->getTerminator()),
|
|
|
|
|
|
|
|
nan_op0);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* compare to NaN interval */
|
|
|
|
|
|
|
|
Instruction *is_op0_nan =
|
|
|
|
|
|
|
|
CmpInst::Create(Instruction::ICmp, CmpInst::ICMP_UGT, nan_op0,
|
|
|
|
|
|
|
|
ConstantInt::get(intType, NaN_lowend));
|
|
|
|
|
|
|
|
bb->getInstList().insert(BasicBlock::iterator(bb->getTerminator()),
|
|
|
|
|
|
|
|
is_op0_nan);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Check op1 for NaN */
|
|
|
|
/* Check op1 for NaN */
|
|
|
|
/* Shift right 1 Bit, ignore sign bit */
|
|
|
|
/* Shift right 1 Bit, ignore sign bit */
|
|
|
|
nan_op1 = BinaryOperator::Create(Instruction::Shl, bpre_op1,
|
|
|
|
nan_op1 = BinaryOperator::Create(Instruction::Shl, bpre_op1,
|
|
|
|
ConstantInt::get(bpre_op1->getType(), 1));
|
|
|
|
ConstantInt::get(bpre_op1->getType(), 1));
|
|
|
|
bb->getInstList().insert(BasicBlock::iterator(bb->getTerminator()),
|
|
|
|
/* compare to NaN interval */
|
|
|
|
nan_op1);
|
|
|
|
Instruction *is_op0_nan =
|
|
|
|
|
|
|
|
CmpInst::Create(Instruction::ICmp, CmpInst::ICMP_UGT, nan_op0,
|
|
|
|
|
|
|
|
ConstantInt::get(intType, NaN_lowend));
|
|
|
|
/* compare to NaN interval */
|
|
|
|
/* compare to NaN interval */
|
|
|
|
Instruction *is_op1_nan =
|
|
|
|
Instruction *is_op1_nan =
|
|
|
|
CmpInst::Create(Instruction::ICmp, CmpInst::ICMP_UGT, nan_op1,
|
|
|
|
CmpInst::Create(Instruction::ICmp, CmpInst::ICMP_UGT, nan_op1,
|
|
|
|
ConstantInt::get(intType, NaN_lowend));
|
|
|
|
ConstantInt::get(intType, NaN_lowend));
|
|
|
|
bb->getInstList().insert(BasicBlock::iterator(bb->getTerminator()),
|
|
|
|
|
|
|
|
is_op1_nan);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* combine checks */
|
|
|
|
/* combine checks */
|
|
|
|
Instruction *is_nan =
|
|
|
|
Instruction *is_nan =
|
|
|
|
BinaryOperator::Create(Instruction::Or, is_op0_nan, is_op1_nan);
|
|
|
|
BinaryOperator::Create(Instruction::Or, is_op0_nan, is_op1_nan);
|
|
|
|
|
|
|
|
#if LLVM_MAJOR >= 16
|
|
|
|
|
|
|
|
nan_op0->insertInto(bb, BasicBlock::iterator(bb->getTerminator()));
|
|
|
|
|
|
|
|
is_op0_nan->insertInto(bb, BasicBlock::iterator(bb->getTerminator()));
|
|
|
|
|
|
|
|
nan_op1->insertInto(bb, BasicBlock::iterator(bb->getTerminator()));
|
|
|
|
|
|
|
|
is_op1_nan->insertInto(bb, BasicBlock::iterator(bb->getTerminator()));
|
|
|
|
|
|
|
|
is_nan->insertInto(bb, BasicBlock::iterator(bb->getTerminator()));
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
bb->getInstList().insert(BasicBlock::iterator(bb->getTerminator()),
|
|
|
|
|
|
|
|
nan_op0);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bb->getInstList().insert(BasicBlock::iterator(bb->getTerminator()),
|
|
|
|
|
|
|
|
is_op0_nan);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bb->getInstList().insert(BasicBlock::iterator(bb->getTerminator()),
|
|
|
|
|
|
|
|
nan_op1);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bb->getInstList().insert(BasicBlock::iterator(bb->getTerminator()),
|
|
|
|
|
|
|
|
is_op1_nan);
|
|
|
|
|
|
|
|
|
|
|
|
bb->getInstList().insert(BasicBlock::iterator(bb->getTerminator()), is_nan);
|
|
|
|
bb->getInstList().insert(BasicBlock::iterator(bb->getTerminator()), is_nan);
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
/* the result of the comparison, when at least one op is NaN
|
|
|
|
/* the result of the comparison, when at least one op is NaN
|
|
|
|
is true only for the "NOT EQUAL" predicates. */
|
|
|
|
is true only for the "NOT EQUAL" predicates. */
|
|
|
@ -1079,23 +1145,30 @@ size_t SplitComparesTransform::splitFPCompares(Module &M) {
|
|
|
|
|
|
|
|
|
|
|
|
isMzero_op0 = CmpInst::Create(Instruction::ICmp, CmpInst::ICMP_EQ, bpre_op0,
|
|
|
|
isMzero_op0 = CmpInst::Create(Instruction::ICmp, CmpInst::ICMP_EQ, bpre_op0,
|
|
|
|
ConstantInt::get(intType, MinusZero));
|
|
|
|
ConstantInt::get(intType, MinusZero));
|
|
|
|
|
|
|
|
isMzero_op1 = CmpInst::Create(Instruction::ICmp, CmpInst::ICMP_EQ, bpre_op1,
|
|
|
|
|
|
|
|
ConstantInt::get(intType, MinusZero));
|
|
|
|
|
|
|
|
b_op0 = SelectInst::Create(isMzero_op0, ConstantInt::get(intType, PlusZero),
|
|
|
|
|
|
|
|
bpre_op0);
|
|
|
|
|
|
|
|
b_op1 = SelectInst::Create(isMzero_op1, ConstantInt::get(intType, PlusZero),
|
|
|
|
|
|
|
|
bpre_op1);
|
|
|
|
|
|
|
|
#if LLVM_MAJOR >= 16
|
|
|
|
|
|
|
|
isMzero_op0->insertInto(nonan_bb, BasicBlock::iterator(nonan_bb->getTerminator()));
|
|
|
|
|
|
|
|
isMzero_op1->insertInto(nonan_bb, BasicBlock::iterator(nonan_bb->getTerminator()));
|
|
|
|
|
|
|
|
b_op0->insertInto(nonan_bb, BasicBlock::iterator(nonan_bb->getTerminator()));
|
|
|
|
|
|
|
|
b_op1->insertInto(nonan_bb, BasicBlock::iterator(nonan_bb->getTerminator()));
|
|
|
|
|
|
|
|
#else
|
|
|
|
nonan_bb->getInstList().insert(
|
|
|
|
nonan_bb->getInstList().insert(
|
|
|
|
BasicBlock::iterator(nonan_bb->getTerminator()), isMzero_op0);
|
|
|
|
BasicBlock::iterator(nonan_bb->getTerminator()), isMzero_op0);
|
|
|
|
|
|
|
|
|
|
|
|
isMzero_op1 = CmpInst::Create(Instruction::ICmp, CmpInst::ICMP_EQ, bpre_op1,
|
|
|
|
|
|
|
|
ConstantInt::get(intType, MinusZero));
|
|
|
|
|
|
|
|
nonan_bb->getInstList().insert(
|
|
|
|
nonan_bb->getInstList().insert(
|
|
|
|
BasicBlock::iterator(nonan_bb->getTerminator()), isMzero_op1);
|
|
|
|
BasicBlock::iterator(nonan_bb->getTerminator()), isMzero_op1);
|
|
|
|
|
|
|
|
|
|
|
|
b_op0 = SelectInst::Create(isMzero_op0, ConstantInt::get(intType, PlusZero),
|
|
|
|
|
|
|
|
bpre_op0);
|
|
|
|
|
|
|
|
nonan_bb->getInstList().insert(
|
|
|
|
nonan_bb->getInstList().insert(
|
|
|
|
BasicBlock::iterator(nonan_bb->getTerminator()), b_op0);
|
|
|
|
BasicBlock::iterator(nonan_bb->getTerminator()), b_op0);
|
|
|
|
|
|
|
|
|
|
|
|
b_op1 = SelectInst::Create(isMzero_op1, ConstantInt::get(intType, PlusZero),
|
|
|
|
|
|
|
|
bpre_op1);
|
|
|
|
|
|
|
|
nonan_bb->getInstList().insert(
|
|
|
|
nonan_bb->getInstList().insert(
|
|
|
|
BasicBlock::iterator(nonan_bb->getTerminator()), b_op1);
|
|
|
|
BasicBlock::iterator(nonan_bb->getTerminator()), b_op1);
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
/* isolate signs of value of floating point type */
|
|
|
|
/* isolate signs of value of floating point type */
|
|
|
|
|
|
|
|
|
|
|
@ -1106,26 +1179,34 @@ size_t SplitComparesTransform::splitFPCompares(Module &M) {
|
|
|
|
s_s0 =
|
|
|
|
s_s0 =
|
|
|
|
BinaryOperator::Create(Instruction::LShr, b_op0,
|
|
|
|
BinaryOperator::Create(Instruction::LShr, b_op0,
|
|
|
|
ConstantInt::get(b_op0->getType(), op_size - 1));
|
|
|
|
ConstantInt::get(b_op0->getType(), op_size - 1));
|
|
|
|
nonan_bb->getInstList().insert(
|
|
|
|
|
|
|
|
BasicBlock::iterator(nonan_bb->getTerminator()), s_s0);
|
|
|
|
|
|
|
|
t_s0 = new TruncInst(s_s0, Int1Ty);
|
|
|
|
|
|
|
|
nonan_bb->getInstList().insert(
|
|
|
|
|
|
|
|
BasicBlock::iterator(nonan_bb->getTerminator()), t_s0);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
s_s1 =
|
|
|
|
s_s1 =
|
|
|
|
BinaryOperator::Create(Instruction::LShr, b_op1,
|
|
|
|
BinaryOperator::Create(Instruction::LShr, b_op1,
|
|
|
|
ConstantInt::get(b_op1->getType(), op_size - 1));
|
|
|
|
ConstantInt::get(b_op1->getType(), op_size - 1));
|
|
|
|
nonan_bb->getInstList().insert(
|
|
|
|
t_s0 = new TruncInst(s_s0, Int1Ty);
|
|
|
|
BasicBlock::iterator(nonan_bb->getTerminator()), s_s1);
|
|
|
|
|
|
|
|
t_s1 = new TruncInst(s_s1, Int1Ty);
|
|
|
|
t_s1 = new TruncInst(s_s1, Int1Ty);
|
|
|
|
nonan_bb->getInstList().insert(
|
|
|
|
|
|
|
|
BasicBlock::iterator(nonan_bb->getTerminator()), t_s1);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* compare of the sign bits */
|
|
|
|
/* compare of the sign bits */
|
|
|
|
icmp_sign_bit =
|
|
|
|
icmp_sign_bit =
|
|
|
|
CmpInst::Create(Instruction::ICmp, CmpInst::ICMP_EQ, t_s0, t_s1);
|
|
|
|
CmpInst::Create(Instruction::ICmp, CmpInst::ICMP_EQ, t_s0, t_s1);
|
|
|
|
|
|
|
|
#if LLVM_MAJOR >= 16
|
|
|
|
|
|
|
|
s_s0->insertInto(nonan_bb, BasicBlock::iterator(nonan_bb->getTerminator()));
|
|
|
|
|
|
|
|
t_s0->insertInto(nonan_bb, BasicBlock::iterator(nonan_bb->getTerminator()));
|
|
|
|
|
|
|
|
s_s1->insertInto(nonan_bb, BasicBlock::iterator(nonan_bb->getTerminator()));
|
|
|
|
|
|
|
|
t_s1->insertInto(nonan_bb, BasicBlock::iterator(nonan_bb->getTerminator()));
|
|
|
|
|
|
|
|
icmp_sign_bit->insertInto(nonan_bb, BasicBlock::iterator(nonan_bb->getTerminator()));
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
nonan_bb->getInstList().insert(
|
|
|
|
|
|
|
|
BasicBlock::iterator(nonan_bb->getTerminator()), s_s0);
|
|
|
|
|
|
|
|
nonan_bb->getInstList().insert(
|
|
|
|
|
|
|
|
BasicBlock::iterator(nonan_bb->getTerminator()), t_s0);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
nonan_bb->getInstList().insert(
|
|
|
|
|
|
|
|
BasicBlock::iterator(nonan_bb->getTerminator()), s_s1);
|
|
|
|
|
|
|
|
nonan_bb->getInstList().insert(
|
|
|
|
|
|
|
|
BasicBlock::iterator(nonan_bb->getTerminator()), t_s1);
|
|
|
|
|
|
|
|
|
|
|
|
nonan_bb->getInstList().insert(
|
|
|
|
nonan_bb->getInstList().insert(
|
|
|
|
BasicBlock::iterator(nonan_bb->getTerminator()), icmp_sign_bit);
|
|
|
|
BasicBlock::iterator(nonan_bb->getTerminator()), icmp_sign_bit);
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
/* create a new basic block which is executed if the signedness bits are
|
|
|
|
/* create a new basic block which is executed if the signedness bits are
|
|
|
|
* equal */
|
|
|
|
* equal */
|
|
|
@ -1157,17 +1238,28 @@ size_t SplitComparesTransform::splitFPCompares(Module &M) {
|
|
|
|
s_e1 = BinaryOperator::Create(
|
|
|
|
s_e1 = BinaryOperator::Create(
|
|
|
|
Instruction::LShr, b_op1,
|
|
|
|
Instruction::LShr, b_op1,
|
|
|
|
ConstantInt::get(b_op1->getType(), shiftR_exponent));
|
|
|
|
ConstantInt::get(b_op1->getType(), shiftR_exponent));
|
|
|
|
|
|
|
|
#if LLVM_MAJOR >= 16
|
|
|
|
|
|
|
|
s_e0->insertInto(signequal_bb, BasicBlock::iterator(signequal_bb->getTerminator()));
|
|
|
|
|
|
|
|
s_e1->insertInto(signequal_bb, BasicBlock::iterator(signequal_bb->getTerminator()));
|
|
|
|
|
|
|
|
#else
|
|
|
|
signequal_bb->getInstList().insert(
|
|
|
|
signequal_bb->getInstList().insert(
|
|
|
|
BasicBlock::iterator(signequal_bb->getTerminator()), s_e0);
|
|
|
|
BasicBlock::iterator(signequal_bb->getTerminator()), s_e0);
|
|
|
|
signequal_bb->getInstList().insert(
|
|
|
|
signequal_bb->getInstList().insert(
|
|
|
|
BasicBlock::iterator(signequal_bb->getTerminator()), s_e1);
|
|
|
|
BasicBlock::iterator(signequal_bb->getTerminator()), s_e1);
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
t_e0 = new TruncInst(s_e0, IntExponentTy);
|
|
|
|
t_e0 = new TruncInst(s_e0, IntExponentTy);
|
|
|
|
t_e1 = new TruncInst(s_e1, IntExponentTy);
|
|
|
|
t_e1 = new TruncInst(s_e1, IntExponentTy);
|
|
|
|
|
|
|
|
#if LLVM_MAJOR >= 16
|
|
|
|
|
|
|
|
t_e0->insertInto(signequal_bb, BasicBlock::iterator(signequal_bb->getTerminator()));
|
|
|
|
|
|
|
|
t_e1->insertInto(signequal_bb, BasicBlock::iterator(signequal_bb->getTerminator()));
|
|
|
|
|
|
|
|
#else
|
|
|
|
signequal_bb->getInstList().insert(
|
|
|
|
signequal_bb->getInstList().insert(
|
|
|
|
BasicBlock::iterator(signequal_bb->getTerminator()), t_e0);
|
|
|
|
BasicBlock::iterator(signequal_bb->getTerminator()), t_e0);
|
|
|
|
signequal_bb->getInstList().insert(
|
|
|
|
signequal_bb->getInstList().insert(
|
|
|
|
BasicBlock::iterator(signequal_bb->getTerminator()), t_e1);
|
|
|
|
BasicBlock::iterator(signequal_bb->getTerminator()), t_e1);
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (sizeInBits - precision < exTySizeBytes * 8) {
|
|
|
|
if (sizeInBits - precision < exTySizeBytes * 8) {
|
|
|
|
|
|
|
|
|
|
|
@ -1177,10 +1269,15 @@ size_t SplitComparesTransform::splitFPCompares(Module &M) {
|
|
|
|
m_e1 = BinaryOperator::Create(
|
|
|
|
m_e1 = BinaryOperator::Create(
|
|
|
|
Instruction::And, t_e1,
|
|
|
|
Instruction::And, t_e1,
|
|
|
|
ConstantInt::get(t_e1->getType(), mask_exponent));
|
|
|
|
ConstantInt::get(t_e1->getType(), mask_exponent));
|
|
|
|
|
|
|
|
#if LLVM_MAJOR >= 16
|
|
|
|
|
|
|
|
m_e0->insertInto(signequal_bb, BasicBlock::iterator(signequal_bb->getTerminator()));
|
|
|
|
|
|
|
|
m_e1->insertInto(signequal_bb, BasicBlock::iterator(signequal_bb->getTerminator()));
|
|
|
|
|
|
|
|
#else
|
|
|
|
signequal_bb->getInstList().insert(
|
|
|
|
signequal_bb->getInstList().insert(
|
|
|
|
BasicBlock::iterator(signequal_bb->getTerminator()), m_e0);
|
|
|
|
BasicBlock::iterator(signequal_bb->getTerminator()), m_e0);
|
|
|
|
signequal_bb->getInstList().insert(
|
|
|
|
signequal_bb->getInstList().insert(
|
|
|
|
BasicBlock::iterator(signequal_bb->getTerminator()), m_e1);
|
|
|
|
BasicBlock::iterator(signequal_bb->getTerminator()), m_e1);
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
|
|
|
|
|
|
|
@ -1214,9 +1311,13 @@ size_t SplitComparesTransform::splitFPCompares(Module &M) {
|
|
|
|
Instruction *icmp_exponent;
|
|
|
|
Instruction *icmp_exponent;
|
|
|
|
icmp_exponents_equal =
|
|
|
|
icmp_exponents_equal =
|
|
|
|
CmpInst::Create(Instruction::ICmp, CmpInst::ICMP_EQ, m_e0, m_e1);
|
|
|
|
CmpInst::Create(Instruction::ICmp, CmpInst::ICMP_EQ, m_e0, m_e1);
|
|
|
|
|
|
|
|
#if LLVM_MAJOR >= 16
|
|
|
|
|
|
|
|
icmp_exponents_equal->insertInto(signequal_bb, BasicBlock::iterator(signequal_bb->getTerminator()));
|
|
|
|
|
|
|
|
#else
|
|
|
|
signequal_bb->getInstList().insert(
|
|
|
|
signequal_bb->getInstList().insert(
|
|
|
|
BasicBlock::iterator(signequal_bb->getTerminator()),
|
|
|
|
BasicBlock::iterator(signequal_bb->getTerminator()),
|
|
|
|
icmp_exponents_equal);
|
|
|
|
icmp_exponents_equal);
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
// shortcut for unequal exponents
|
|
|
|
// shortcut for unequal exponents
|
|
|
|
signequal2_bb = signequal_bb->splitBasicBlock(
|
|
|
|
signequal2_bb = signequal_bb->splitBasicBlock(
|
|
|
@ -1230,9 +1331,13 @@ size_t SplitComparesTransform::splitFPCompares(Module &M) {
|
|
|
|
|
|
|
|
|
|
|
|
icmp_exponent =
|
|
|
|
icmp_exponent =
|
|
|
|
CmpInst::Create(Instruction::ICmp, CmpInst::ICMP_UGT, m_e0, m_e1);
|
|
|
|
CmpInst::Create(Instruction::ICmp, CmpInst::ICMP_UGT, m_e0, m_e1);
|
|
|
|
|
|
|
|
#if LLVM_MAJOR >= 16
|
|
|
|
|
|
|
|
icmp_exponent->insertInto(signequal2_bb, BasicBlock::iterator(signequal2_bb->getTerminator()));
|
|
|
|
|
|
|
|
#else
|
|
|
|
signequal2_bb->getInstList().insert(
|
|
|
|
signequal2_bb->getInstList().insert(
|
|
|
|
BasicBlock::iterator(signequal2_bb->getTerminator()),
|
|
|
|
BasicBlock::iterator(signequal2_bb->getTerminator()),
|
|
|
|
icmp_exponent);
|
|
|
|
icmp_exponent);
|
|
|
|
|
|
|
|
#endif
|
|
|
|
icmp_exponent_result =
|
|
|
|
icmp_exponent_result =
|
|
|
|
BinaryOperator::Create(Instruction::Xor, icmp_exponent, t_s0);
|
|
|
|
BinaryOperator::Create(Instruction::Xor, icmp_exponent, t_s0);
|
|
|
|
break;
|
|
|
|
break;
|
|
|
@ -1240,9 +1345,13 @@ size_t SplitComparesTransform::splitFPCompares(Module &M) {
|
|
|
|
case CmpInst::FCMP_ULT:
|
|
|
|
case CmpInst::FCMP_ULT:
|
|
|
|
icmp_exponents_equal =
|
|
|
|
icmp_exponents_equal =
|
|
|
|
CmpInst::Create(Instruction::ICmp, CmpInst::ICMP_EQ, m_e0, m_e1);
|
|
|
|
CmpInst::Create(Instruction::ICmp, CmpInst::ICMP_EQ, m_e0, m_e1);
|
|
|
|
|
|
|
|
#if LLVM_MAJOR >= 16
|
|
|
|
|
|
|
|
icmp_exponents_equal->insertInto(signequal_bb, BasicBlock::iterator(signequal_bb->getTerminator()));
|
|
|
|
|
|
|
|
#else
|
|
|
|
signequal_bb->getInstList().insert(
|
|
|
|
signequal_bb->getInstList().insert(
|
|
|
|
BasicBlock::iterator(signequal_bb->getTerminator()),
|
|
|
|
BasicBlock::iterator(signequal_bb->getTerminator()),
|
|
|
|
icmp_exponents_equal);
|
|
|
|
icmp_exponents_equal);
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
// shortcut for unequal exponents
|
|
|
|
// shortcut for unequal exponents
|
|
|
|
signequal2_bb = signequal_bb->splitBasicBlock(
|
|
|
|
signequal2_bb = signequal_bb->splitBasicBlock(
|
|
|
@ -1256,9 +1365,13 @@ size_t SplitComparesTransform::splitFPCompares(Module &M) {
|
|
|
|
|
|
|
|
|
|
|
|
icmp_exponent =
|
|
|
|
icmp_exponent =
|
|
|
|
CmpInst::Create(Instruction::ICmp, CmpInst::ICMP_ULT, m_e0, m_e1);
|
|
|
|
CmpInst::Create(Instruction::ICmp, CmpInst::ICMP_ULT, m_e0, m_e1);
|
|
|
|
|
|
|
|
#if LLVM_MAJOR >= 16
|
|
|
|
|
|
|
|
icmp_exponent->insertInto(signequal2_bb, BasicBlock::iterator(signequal2_bb->getTerminator()));
|
|
|
|
|
|
|
|
#else
|
|
|
|
signequal2_bb->getInstList().insert(
|
|
|
|
signequal2_bb->getInstList().insert(
|
|
|
|
BasicBlock::iterator(signequal2_bb->getTerminator()),
|
|
|
|
BasicBlock::iterator(signequal2_bb->getTerminator()),
|
|
|
|
icmp_exponent);
|
|
|
|
icmp_exponent);
|
|
|
|
|
|
|
|
#endif
|
|
|
|
icmp_exponent_result =
|
|
|
|
icmp_exponent_result =
|
|
|
|
BinaryOperator::Create(Instruction::Xor, icmp_exponent, t_s0);
|
|
|
|
BinaryOperator::Create(Instruction::Xor, icmp_exponent, t_s0);
|
|
|
|
break;
|
|
|
|
break;
|
|
|
@ -1267,9 +1380,13 @@ size_t SplitComparesTransform::splitFPCompares(Module &M) {
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#if LLVM_MAJOR >= 16
|
|
|
|
|
|
|
|
icmp_exponent_result->insertInto(signequal2_bb, BasicBlock::iterator(signequal2_bb->getTerminator()));
|
|
|
|
|
|
|
|
#else
|
|
|
|
signequal2_bb->getInstList().insert(
|
|
|
|
signequal2_bb->getInstList().insert(
|
|
|
|
BasicBlock::iterator(signequal2_bb->getTerminator()),
|
|
|
|
BasicBlock::iterator(signequal2_bb->getTerminator()),
|
|
|
|
icmp_exponent_result);
|
|
|
|
icmp_exponent_result);
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
@ -1319,19 +1436,29 @@ size_t SplitComparesTransform::splitFPCompares(Module &M) {
|
|
|
|
m_f1 = BinaryOperator::Create(
|
|
|
|
m_f1 = BinaryOperator::Create(
|
|
|
|
Instruction::And, b_op1,
|
|
|
|
Instruction::And, b_op1,
|
|
|
|
ConstantInt::get(b_op1->getType(), mask_fraction));
|
|
|
|
ConstantInt::get(b_op1->getType(), mask_fraction));
|
|
|
|
|
|
|
|
#if LLVM_MAJOR >= 16
|
|
|
|
|
|
|
|
m_f0->insertInto(middle_bb, BasicBlock::iterator(middle_bb->getTerminator()));
|
|
|
|
|
|
|
|
m_f1->insertInto(middle_bb, BasicBlock::iterator(middle_bb->getTerminator()));
|
|
|
|
|
|
|
|
#else
|
|
|
|
middle_bb->getInstList().insert(
|
|
|
|
middle_bb->getInstList().insert(
|
|
|
|
BasicBlock::iterator(middle_bb->getTerminator()), m_f0);
|
|
|
|
BasicBlock::iterator(middle_bb->getTerminator()), m_f0);
|
|
|
|
middle_bb->getInstList().insert(
|
|
|
|
middle_bb->getInstList().insert(
|
|
|
|
BasicBlock::iterator(middle_bb->getTerminator()), m_f1);
|
|
|
|
BasicBlock::iterator(middle_bb->getTerminator()), m_f1);
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
if (needTrunc) {
|
|
|
|
if (needTrunc) {
|
|
|
|
|
|
|
|
|
|
|
|
t_f0 = new TruncInst(m_f0, IntFractionTy);
|
|
|
|
t_f0 = new TruncInst(m_f0, IntFractionTy);
|
|
|
|
t_f1 = new TruncInst(m_f1, IntFractionTy);
|
|
|
|
t_f1 = new TruncInst(m_f1, IntFractionTy);
|
|
|
|
|
|
|
|
#if LLVM_MAJOR >= 16
|
|
|
|
|
|
|
|
t_f0->insertInto(middle_bb, BasicBlock::iterator(middle_bb->getTerminator()));
|
|
|
|
|
|
|
|
t_f1->insertInto(middle_bb, BasicBlock::iterator(middle_bb->getTerminator()));
|
|
|
|
|
|
|
|
#else
|
|
|
|
middle_bb->getInstList().insert(
|
|
|
|
middle_bb->getInstList().insert(
|
|
|
|
BasicBlock::iterator(middle_bb->getTerminator()), t_f0);
|
|
|
|
BasicBlock::iterator(middle_bb->getTerminator()), t_f0);
|
|
|
|
middle_bb->getInstList().insert(
|
|
|
|
middle_bb->getInstList().insert(
|
|
|
|
BasicBlock::iterator(middle_bb->getTerminator()), t_f1);
|
|
|
|
BasicBlock::iterator(middle_bb->getTerminator()), t_f1);
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
|
|
|
|
|
|
|
@ -1346,10 +1473,15 @@ size_t SplitComparesTransform::splitFPCompares(Module &M) {
|
|
|
|
|
|
|
|
|
|
|
|
t_f0 = new TruncInst(b_op0, IntFractionTy);
|
|
|
|
t_f0 = new TruncInst(b_op0, IntFractionTy);
|
|
|
|
t_f1 = new TruncInst(b_op1, IntFractionTy);
|
|
|
|
t_f1 = new TruncInst(b_op1, IntFractionTy);
|
|
|
|
|
|
|
|
#if LLVM_MAJOR >= 16
|
|
|
|
|
|
|
|
t_f0->insertInto(middle_bb, BasicBlock::iterator(middle_bb->getTerminator()));
|
|
|
|
|
|
|
|
t_f1->insertInto(middle_bb, BasicBlock::iterator(middle_bb->getTerminator()));
|
|
|
|
|
|
|
|
#else
|
|
|
|
middle_bb->getInstList().insert(
|
|
|
|
middle_bb->getInstList().insert(
|
|
|
|
BasicBlock::iterator(middle_bb->getTerminator()), t_f0);
|
|
|
|
BasicBlock::iterator(middle_bb->getTerminator()), t_f0);
|
|
|
|
middle_bb->getInstList().insert(
|
|
|
|
middle_bb->getInstList().insert(
|
|
|
|
BasicBlock::iterator(middle_bb->getTerminator()), t_f1);
|
|
|
|
BasicBlock::iterator(middle_bb->getTerminator()), t_f1);
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
|
|
|
|
|
|
|
@ -1370,18 +1502,26 @@ size_t SplitComparesTransform::splitFPCompares(Module &M) {
|
|
|
|
case CmpInst::FCMP_OEQ:
|
|
|
|
case CmpInst::FCMP_OEQ:
|
|
|
|
icmp_fraction_result =
|
|
|
|
icmp_fraction_result =
|
|
|
|
CmpInst::Create(Instruction::ICmp, CmpInst::ICMP_EQ, t_f0, t_f1);
|
|
|
|
CmpInst::Create(Instruction::ICmp, CmpInst::ICMP_EQ, t_f0, t_f1);
|
|
|
|
|
|
|
|
#if LLVM_MAJOR >= 16
|
|
|
|
|
|
|
|
icmp_fraction_result->insertInto(middle2_bb, BasicBlock::iterator(middle2_bb->getTerminator()));
|
|
|
|
|
|
|
|
#else
|
|
|
|
middle2_bb->getInstList().insert(
|
|
|
|
middle2_bb->getInstList().insert(
|
|
|
|
BasicBlock::iterator(middle2_bb->getTerminator()),
|
|
|
|
BasicBlock::iterator(middle2_bb->getTerminator()),
|
|
|
|
icmp_fraction_result);
|
|
|
|
icmp_fraction_result);
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case CmpInst::FCMP_UNE:
|
|
|
|
case CmpInst::FCMP_UNE:
|
|
|
|
case CmpInst::FCMP_ONE:
|
|
|
|
case CmpInst::FCMP_ONE:
|
|
|
|
icmp_fraction_result =
|
|
|
|
icmp_fraction_result =
|
|
|
|
CmpInst::Create(Instruction::ICmp, CmpInst::ICMP_NE, t_f0, t_f1);
|
|
|
|
CmpInst::Create(Instruction::ICmp, CmpInst::ICMP_NE, t_f0, t_f1);
|
|
|
|
|
|
|
|
#if LLVM_MAJOR >= 16
|
|
|
|
|
|
|
|
icmp_fraction_result->insertInto(middle2_bb, BasicBlock::iterator(middle2_bb->getTerminator()));
|
|
|
|
|
|
|
|
#else
|
|
|
|
middle2_bb->getInstList().insert(
|
|
|
|
middle2_bb->getInstList().insert(
|
|
|
|
BasicBlock::iterator(middle2_bb->getTerminator()),
|
|
|
|
BasicBlock::iterator(middle2_bb->getTerminator()),
|
|
|
|
icmp_fraction_result);
|
|
|
|
icmp_fraction_result);
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case CmpInst::FCMP_OGT:
|
|
|
|
case CmpInst::FCMP_OGT:
|
|
|
@ -1402,21 +1542,31 @@ size_t SplitComparesTransform::splitFPCompares(Module &M) {
|
|
|
|
if (FcmpInst->getPredicate() == CmpInst::FCMP_OGT ||
|
|
|
|
if (FcmpInst->getPredicate() == CmpInst::FCMP_OGT ||
|
|
|
|
FcmpInst->getPredicate() == CmpInst::FCMP_UGT) {
|
|
|
|
FcmpInst->getPredicate() == CmpInst::FCMP_UGT) {
|
|
|
|
|
|
|
|
|
|
|
|
negative_bb->getInstList().push_back(
|
|
|
|
icmp_fraction_result = CmpInst::Create(
|
|
|
|
icmp_fraction_result = CmpInst::Create(
|
|
|
|
Instruction::ICmp, CmpInst::ICMP_ULT, t_f0, t_f1);
|
|
|
|
Instruction::ICmp, CmpInst::ICMP_ULT, t_f0, t_f1));
|
|
|
|
icmp_fraction_result2 = CmpInst::Create(
|
|
|
|
positive_bb->getInstList().push_back(
|
|
|
|
Instruction::ICmp, CmpInst::ICMP_UGT, t_f0, t_f1);
|
|
|
|
icmp_fraction_result2 = CmpInst::Create(
|
|
|
|
#if LLVM_MAJOR >= 16
|
|
|
|
Instruction::ICmp, CmpInst::ICMP_UGT, t_f0, t_f1));
|
|
|
|
icmp_fraction_result->insertInto(negative_bb, negative_bb->end());
|
|
|
|
|
|
|
|
icmp_fraction_result2->insertInto(positive_bb, negative_bb->end());
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
negative_bb->getInstList().push_back(icmp_fraction_result);
|
|
|
|
|
|
|
|
positive_bb->getInstList().push_back(icmp_fraction_result2);
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
|
|
|
|
|
|
|
|
negative_bb->getInstList().push_back(
|
|
|
|
icmp_fraction_result = CmpInst::Create(
|
|
|
|
icmp_fraction_result = CmpInst::Create(
|
|
|
|
Instruction::ICmp, CmpInst::ICMP_UGT, t_f0, t_f1);
|
|
|
|
Instruction::ICmp, CmpInst::ICMP_UGT, t_f0, t_f1));
|
|
|
|
icmp_fraction_result2 = CmpInst::Create(
|
|
|
|
positive_bb->getInstList().push_back(
|
|
|
|
Instruction::ICmp, CmpInst::ICMP_ULT, t_f0, t_f1);
|
|
|
|
icmp_fraction_result2 = CmpInst::Create(
|
|
|
|
#if LLVM_MAJOR >= 16
|
|
|
|
Instruction::ICmp, CmpInst::ICMP_ULT, t_f0, t_f1));
|
|
|
|
icmp_fraction_result->insertInto(negative_bb, negative_bb->end());
|
|
|
|
|
|
|
|
icmp_fraction_result2->insertInto(positive_bb, negative_bb->end());
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
negative_bb->getInstList().push_back(icmp_fraction_result);
|
|
|
|
|
|
|
|
positive_bb->getInstList().push_back(icmp_fraction_result2);
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -1430,8 +1580,12 @@ size_t SplitComparesTransform::splitFPCompares(Module &M) {
|
|
|
|
PN2 = PHINode::Create(Int1Ty, 2, "");
|
|
|
|
PN2 = PHINode::Create(Int1Ty, 2, "");
|
|
|
|
PN2->addIncoming(icmp_fraction_result, negative_bb);
|
|
|
|
PN2->addIncoming(icmp_fraction_result, negative_bb);
|
|
|
|
PN2->addIncoming(icmp_fraction_result2, positive_bb);
|
|
|
|
PN2->addIncoming(icmp_fraction_result2, positive_bb);
|
|
|
|
|
|
|
|
#if LLVM_MAJOR >= 16
|
|
|
|
|
|
|
|
PN2->insertInto(middle2_bb, BasicBlock::iterator(middle2_bb->getTerminator()));
|
|
|
|
|
|
|
|
#else
|
|
|
|
middle2_bb->getInstList().insert(
|
|
|
|
middle2_bb->getInstList().insert(
|
|
|
|
BasicBlock::iterator(middle2_bb->getTerminator()), PN2);
|
|
|
|
BasicBlock::iterator(middle2_bb->getTerminator()), PN2);
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
} break;
|
|
|
|
} break;
|
|
|
|
|
|
|
|
|
|
|
@ -1494,7 +1648,11 @@ size_t SplitComparesTransform::splitFPCompares(Module &M) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
BasicBlock::iterator ii(FcmpInst);
|
|
|
|
BasicBlock::iterator ii(FcmpInst);
|
|
|
|
|
|
|
|
#if LLVM_MAJOR >= 16
|
|
|
|
|
|
|
|
ReplaceInstWithInst(FcmpInst->getParent(), ii, PN);
|
|
|
|
|
|
|
|
#else
|
|
|
|
ReplaceInstWithInst(FcmpInst->getParent()->getInstList(), ii, PN);
|
|
|
|
ReplaceInstWithInst(FcmpInst->getParent()->getInstList(), ii, PN);
|
|
|
|
|
|
|
|
#endif
|
|
|
|
++count;
|
|
|
|
++count;
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|