@@ -1897,41 +1897,46 @@ Instruction *InstCombinerImpl::visitFDiv(BinaryOperator &I) {
18971897 CallBase *Op1AsCallBase = dyn_cast<CallBase>(Op1);
18981898 LibFunc Op0LibFunc, Op1LibFunc;
18991899
1900- TLI.getLibFunc (*Op1AsCallBase, Op1LibFunc);
1901- TLI.getLibFunc (*Op0AsCallBase, Op0LibFunc);
1900+ if (Op1AsCallBase && Op0AsCallBase) {
1901+ TLI.getLibFunc (*Op1AsCallBase, Op1LibFunc);
1902+ TLI.getLibFunc (*Op0AsCallBase, Op0LibFunc);
19021903
1903- bool ArgsMatch = match (Op0AsCallBase->getArgOperand (0 ), m_Value (Y)) &&
1904- match (Op1AsCallBase->getArgOperand (0 ), m_Specific (Y));
1904+ bool ArgsMatch = match (Op0AsCallBase->getArgOperand (0 ), m_Value (Y)) &&
1905+ match (Op1AsCallBase->getArgOperand (0 ), m_Specific (Y));
19051906
1906- bool IsTanH =
1907- ArgsMatch &&
1908- ((Op0LibFunc == LibFunc_sinh && Op1LibFunc == LibFunc_cosh) ||
1909- (Op0LibFunc == LibFunc_sinhf && Op1LibFunc == LibFunc_coshf) ||
1910- (Op0LibFunc == LibFunc_sinhl && Op1LibFunc == LibFunc_coshl));
1907+ bool IsTanH =
1908+ ArgsMatch &&
1909+ ((Op0LibFunc == LibFunc_sinh && Op1LibFunc == LibFunc_cosh) ||
1910+ (Op0LibFunc == LibFunc_sinhf && Op1LibFunc == LibFunc_coshf) ||
1911+ (Op0LibFunc == LibFunc_sinhl && Op1LibFunc == LibFunc_coshl));
19111912
1912- bool IsCotH =
1913- !IsTanH && ArgsMatch &&
1914- ((Op1LibFunc == LibFunc_sinh && Op0LibFunc == LibFunc_cosh) ||
1915- (Op1LibFunc == LibFunc_sinhf && Op0LibFunc == LibFunc_coshf) ||
1916- (Op1LibFunc == LibFunc_sinhl && Op0LibFunc == LibFunc_coshl));
1913+ bool IsCotH =
1914+ !IsTanH && ArgsMatch &&
1915+ ((Op1LibFunc == LibFunc_sinh && Op0LibFunc == LibFunc_cosh) ||
1916+ (Op1LibFunc == LibFunc_sinhf && Op0LibFunc == LibFunc_coshf) ||
1917+ (Op1LibFunc == LibFunc_sinhl && Op0LibFunc == LibFunc_coshl));
19171918
1918- if ((IsTanH || IsCotH) && hasFloatFn (M, &TLI, I.getType (), LibFunc_tanh,
1919- LibFunc_tanhf, LibFunc_tanhl)) {
1919+ if ((IsTanH || IsCotH) && hasFloatFn (M, &TLI, I.getType (), LibFunc_tanh,
1920+ LibFunc_tanhf, LibFunc_tanhl)) {
19201921
1921- Value *Res =
1922- GetReplacement (Y, IsCotH, LibFunc_tanh, LibFunc_tanhf, LibFunc_tanhl);
1922+ Value *Res = GetReplacement (Y, IsCotH, LibFunc_tanh, LibFunc_tanhf,
1923+ LibFunc_tanhl);
1924+
1925+ Instruction *Replacement = replaceInstUsesWith (I, Res);
19231926
1924- Instruction *Replacement = replaceInstUsesWith (I, Res);
1927+ if (!Op0AsCallBase->use_empty ())
1928+ Op0AsCallBase->replaceAllUsesWith (
1929+ PoisonValue::get (Op0AsCallBase->getType ()));
19251930
1926- Op0AsCallBase->replaceAllUsesWith (
1927- PoisonValue::get (Op0AsCallBase->getType ()));
1928- Op1AsCallBase->replaceAllUsesWith (
1929- PoisonValue::get (Op1AsCallBase->getType ()));
1931+ if (!Op1AsCallBase->use_empty ())
1932+ Op1AsCallBase->replaceAllUsesWith (
1933+ PoisonValue::get (Op1AsCallBase->getType ()));
19301934
1931- Op0AsCallBase->eraseFromParent ();
1932- Op1AsCallBase->eraseFromParent ();
1935+ Op0AsCallBase->eraseFromParent ();
1936+ Op1AsCallBase->eraseFromParent ();
19331937
1934- return Replacement;
1938+ return Replacement;
1939+ }
19351940 }
19361941 }
19371942
0 commit comments