tree lhs = gimple_assign_lhs (stmt);
unsigned cnt = 0;
+ /* This is should not be used for -O0 nor it is not useful
+ when ter is turned off. */
+ if (!optimize || !flag_tree_ter)
+ return;
+
FOR_EACH_IMM_USE_FAST (use_p, imm_iter, lhs)
{
if (is_gimple_debug (USE_STMT (use_p)))
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-fgimple -O0 -fdump-tree-optimized " } */
+/* PR tree-optimization/116101 */
+
+int __GIMPLE() f(int a, int b, int c, int d, int e)
+{
+ _Bool t;
+ int ff;
+ int gg;
+ int res;
+ t = a == b;
+ ff = t ? a : e;
+ gg = t ? d : b;
+ res = ff+gg;
+ return res;
+}
+
+/* At -O0 we should not duplicate the comparison. */
+/* { dg-final { scan-tree-dump-times " == " 1 "optimized" } } */
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-fgimple -O2 -fdump-tree-optimized " } */
+/* PR middle-end/105715 */
+
+int __GIMPLE() f(int a, int b, int c, int d, int e)
+{
+ _Bool t;
+ int ff;
+ int gg;
+ int res;
+ t = a == b;
+ ff = t ? a : e;
+ gg = t ? d : b;
+ res = ff+gg;
+ return res;
+}
+
+/* At -O2 we should have duplicate the comparison. */
+/* { dg-final { scan-tree-dump-times " == " 2 "optimized" } } */
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-fgimple -O2 -fno-tree-ter -fdump-tree-optimized " } */
+/* PR tree-optimization/116101 */
+
+int __GIMPLE() f(int a, int b, int c, int d, int e)
+{
+ _Bool t;
+ int ff;
+ int gg;
+ int res;
+ t = a == b;
+ ff = t ? a : e;
+ gg = t ? d : b;
+ res = ff+gg;
+ return res;
+}
+
+/* With -fno-tree-ter it is not useful to duplicate the comparison. */
+/* { dg-final { scan-tree-dump-times " == " 1 "optimized" } } */