@@ -1801,46 +1801,8 @@ Constant *llvm::ConstantFoldCompareInstruction(unsigned short pred,
1801
1801
} else if (isa<ConstantFP>(C1) && isa<ConstantFP>(C2)) {
1802
1802
const APFloat &C1V = cast<ConstantFP>(C1)->getValueAPF ();
1803
1803
const APFloat &C2V = cast<ConstantFP>(C2)->getValueAPF ();
1804
- APFloat::cmpResult R = C1V.compare (C2V);
1805
- switch (pred) {
1806
- default : llvm_unreachable (" Invalid FCmp Predicate" );
1807
- case FCmpInst::FCMP_FALSE: return Constant::getNullValue (ResultTy);
1808
- case FCmpInst::FCMP_TRUE: return Constant::getAllOnesValue (ResultTy);
1809
- case FCmpInst::FCMP_UNO:
1810
- return ConstantInt::get (ResultTy, R==APFloat::cmpUnordered);
1811
- case FCmpInst::FCMP_ORD:
1812
- return ConstantInt::get (ResultTy, R!=APFloat::cmpUnordered);
1813
- case FCmpInst::FCMP_UEQ:
1814
- return ConstantInt::get (ResultTy, R==APFloat::cmpUnordered ||
1815
- R==APFloat::cmpEqual);
1816
- case FCmpInst::FCMP_OEQ:
1817
- return ConstantInt::get (ResultTy, R==APFloat::cmpEqual);
1818
- case FCmpInst::FCMP_UNE:
1819
- return ConstantInt::get (ResultTy, R!=APFloat::cmpEqual);
1820
- case FCmpInst::FCMP_ONE:
1821
- return ConstantInt::get (ResultTy, R==APFloat::cmpLessThan ||
1822
- R==APFloat::cmpGreaterThan);
1823
- case FCmpInst::FCMP_ULT:
1824
- return ConstantInt::get (ResultTy, R==APFloat::cmpUnordered ||
1825
- R==APFloat::cmpLessThan);
1826
- case FCmpInst::FCMP_OLT:
1827
- return ConstantInt::get (ResultTy, R==APFloat::cmpLessThan);
1828
- case FCmpInst::FCMP_UGT:
1829
- return ConstantInt::get (ResultTy, R==APFloat::cmpUnordered ||
1830
- R==APFloat::cmpGreaterThan);
1831
- case FCmpInst::FCMP_OGT:
1832
- return ConstantInt::get (ResultTy, R==APFloat::cmpGreaterThan);
1833
- case FCmpInst::FCMP_ULE:
1834
- return ConstantInt::get (ResultTy, R!=APFloat::cmpGreaterThan);
1835
- case FCmpInst::FCMP_OLE:
1836
- return ConstantInt::get (ResultTy, R==APFloat::cmpLessThan ||
1837
- R==APFloat::cmpEqual);
1838
- case FCmpInst::FCMP_UGE:
1839
- return ConstantInt::get (ResultTy, R!=APFloat::cmpLessThan);
1840
- case FCmpInst::FCMP_OGE:
1841
- return ConstantInt::get (ResultTy, R==APFloat::cmpGreaterThan ||
1842
- R==APFloat::cmpEqual);
1843
- }
1804
+ CmpInst::Predicate Predicate = CmpInst::Predicate (pred);
1805
+ return ConstantInt::get (ResultTy, FCmpInst::compare (C1V, C2V, Predicate));
1844
1806
} else if (auto *C1VTy = dyn_cast<VectorType>(C1->getType ())) {
1845
1807
1846
1808
// Fast path for splatted constants.
0 commit comments