Fixed simplification of fma(a, b, c) (#6958)

This commit is contained in:
PKEuS 2015-08-29 20:51:02 +02:00
parent 8d2c4453ad
commit d7853b9963
2 changed files with 10 additions and 13 deletions

View File

@ -8226,13 +8226,10 @@ void Tokenizer::simplifyMathFunctions()
tok->str(strNumber); // insert result into token list
simplifcationMade = true;
} else if (Token::Match(tok, "fma|fmaf|fmal ( %any% , %any% , %any% )")) {
// Simplify: fma(a,b,c) == > ( a ) * ( b ) + ( c )
// get parameters
const std::string& a(tok->strAt(2));
const std::string& b(tok->strAt(4));
const std::string& c(tok->strAt(6));
tok->str("( " + a + " ) * ( " + b + " ) + ( " + c + " )"); // insert result into token list
tok->deleteNext(7); // delete fma call
// Simplify: fma(a,b,c) == > ( a * b + c )
tok->tokAt(3)->str("*");
tok->tokAt(5)->str("+");
tok->deleteThis(); // delete fma call
simplifcationMade = true;
} else if (Token::Match(tok, "sqrt|sqrtf|sqrtl|cbrt|cbrtf|cbrtl ( %num% )")) {
// Simplify: sqrt(0) = 0 and cbrt(0) == 0

View File

@ -7231,15 +7231,15 @@ private:
void simplifyMathFunctions_fma() {
// verify fma(), fmal(), fmaf() - simplifcation
const char code_fma[] ="int f(int a, int b, int c) { return fma(a,b,c); }";
const char expected_fma[] = "int f ( int a , int b , int c ) { return ( a ) * ( b ) + ( c ) ; }";
const char expected_fma[] = "int f ( int a , int b , int c ) { return ( a * b + c ) ; }";
ASSERT_EQUALS(expected_fma, tokenizeAndStringify(code_fma));
const char code_fmaf[] ="float f ( float a , float b , float c ) { return fmaf(a,b,c); }";
const char expected_fmaf[] = "float f ( float a , float b , float c ) { return ( a ) * ( b ) + ( c ) ; }";
const char expected_fmaf[] = "float f ( float a , float b , float c ) { return ( a * b + c ) ; }";
ASSERT_EQUALS(expected_fmaf, tokenizeAndStringify(code_fmaf));
const char code_fmal[] ="long double f ( long double a , long double b , long double c ) { return fmal(a,b,c); }";
const char expected_fmal[] = "long double f ( long double a , long double b , long double c ) { return ( a ) * ( b ) + ( c ) ; }";
const char expected_fmal[] = "long double f ( long double a , long double b , long double c ) { return ( a * b + c ) ; }";
ASSERT_EQUALS(expected_fmal, tokenizeAndStringify(code_fmal));
const char code_fma1[] = "void f() {\n"
@ -7255,9 +7255,9 @@ private:
"} ;";
const char current_fma1[] = "void f ( ) {\n"
"std :: cout << \"fma(1,2,3): \" << ( 1 ) * ( 2 ) + ( 3 ) << std :: endl ;\n"
"std :: cout << \"fmaf(1,2,3): \" << ( 1 ) * ( 2 ) + ( 3 ) << std :: endl ;\n"
"std :: cout << \"fmal(1,2,3): \" << ( 1 ) * ( 2 ) + ( 3 ) << std :: endl ;\n"
"std :: cout << \"fma(1,2,3): \" << ( 1 * 2 + 3 ) << std :: endl ;\n"
"std :: cout << \"fmaf(1,2,3): \" << ( 1 * 2 + 3 ) << std :: endl ;\n"
"std :: cout << \"fmal(1,2,3): \" << ( 1 * 2 + 3 ) << std :: endl ;\n"
"} ;";
TODO_ASSERT_EQUALS(expected_fma1, current_fma1,tokenizeAndStringify(code_fma1));
}