aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorRichard Biener <rguenther@suse.de>2015-09-14 09:40:17 +0000
committerRichard Biener <rguenth@gcc.gnu.org>2015-09-14 09:40:17 +0000
commitcc099b03c01f74b2b8ddf87f93890bdbde2305f9 (patch)
tree0c1dd8f5b516a50f05e46cddd6b3b039265277ae /gcc
parent64106a1a20775c1ceb07cdb553b9e20402c3e6fc (diff)
downloadgcc-cc099b03c01f74b2b8ddf87f93890bdbde2305f9.zip
gcc-cc099b03c01f74b2b8ddf87f93890bdbde2305f9.tar.gz
gcc-cc099b03c01f74b2b8ddf87f93890bdbde2305f9.tar.bz2
match-and-simplify.texi: Update for changed syntax of inner ifs and the new switch expression.
2015-09-14 Richard Biener <rguenther@suse.de> * doc/match-and-simplify.texi: Update for changed syntax of inner ifs and the new switch expression. From-SVN: r227741
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ChangeLog5
-rw-r--r--gcc/doc/match-and-simplify.texi52
2 files changed, 52 insertions, 5 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 7842cfe..9059ffa 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,8 @@
+2015-09-14 Richard Biener <rguenther@suse.de>
+
+ * doc/match-and-simplify.texi: Update for changed syntax
+ of inner ifs and the new switch expression.
+
2015-09-14 Yuri Rumyantsev <ysrumyan@gmail.com>
* config/i386/haswell.md: New file describing Haswell pipeline.
diff --git a/gcc/doc/match-and-simplify.texi b/gcc/doc/match-and-simplify.texi
index 2591ed8..2bf2320 100644
--- a/gcc/doc/match-and-simplify.texi
+++ b/gcc/doc/match-and-simplify.texi
@@ -118,8 +118,8 @@ be a valid GIMPLE operand (so you cannot generate expressions in C code).
@smallexample
(simplify
(trunc_mod integer_zerop@@0 @@1)
- (if (!integer_zerop (@@1)))
- @@0)
+ (if (!integer_zerop (@@1))
+ @@0))
@end smallexample
Here @code{@@0} captures the first operand of the trunc_mod expression
@@ -130,9 +130,11 @@ can be unconstrained or capture expresions or predicates.
This example introduces an optional operand of simplify,
the if-expression. This condition is evaluated after the
expression matched in the IL and is required to evaluate to true
-to enable the replacement expression. The expression operand
-of the @code{if} is a standard C expression which may contain references
-to captures.
+to enable the replacement expression in the second operand
+position. The expression operand of the @code{if} is a standard C
+expression which may contain references to captures. The @code{if}
+has an optional third operand which may contain the replacement
+expression that is enabled when the condition evaluates to false.
A @code{if} expression can be used to specify a common condition
for multiple simplify patterns, avoiding the need
@@ -149,8 +151,48 @@ to repeat that multiple times:
(negate @@1)))
@end smallexample
+Note that @code{if}s in outer position do not have the optional
+else clause but instead have multiple then clauses.
+
Ifs can be nested.
+There exists a @code{switch} expression which can be used to
+chain conditions avoiding nesting @code{if}s too much:
+
+@smallexample
+(simplify
+ (simple_comparison @@0 REAL_CST@@1)
+ (switch
+ /* a CMP (-0) -> a CMP 0 */
+ (if (REAL_VALUE_MINUS_ZERO (TREE_REAL_CST (@@1)))
+ (cmp @@0 @{ build_real (TREE_TYPE (@@1), dconst0); @}))
+ /* x != NaN is always true, other ops are always false. */
+ (if (REAL_VALUE_ISNAN (TREE_REAL_CST (@@1))
+ && ! HONOR_SNANS (@@1))
+ @{ constant_boolean_node (cmp == NE_EXPR, type); @})))
+@end smallexample
+
+Is equal to
+
+@smallexample
+(simplify
+ (simple_comparison @@0 REAL_CST@@1)
+ (switch
+ /* a CMP (-0) -> a CMP 0 */
+ (if (REAL_VALUE_MINUS_ZERO (TREE_REAL_CST (@@1)))
+ (cmp @@0 @{ build_real (TREE_TYPE (@@1), dconst0); @})
+ /* x != NaN is always true, other ops are always false. */
+ (if (REAL_VALUE_ISNAN (TREE_REAL_CST (@@1))
+ && ! HONOR_SNANS (@@1))
+ @{ constant_boolean_node (cmp == NE_EXPR, type); @}))))
+@end smallexample
+
+which has the second @code{if} in the else operand of the first.
+The @code{switch} expression takes @code{if} expressions as
+operands (which may not have else clauses) and as a last operand
+a replacement expression which should be enabled by default if
+no other condition evaluated to true.
+
Captures can also be used for capturing results of sub-expressions.
@smallexample