Index: gcc/tree-ssa-forwprop.c =================================================================== --- gcc/tree-ssa-forwprop.c (revision 196158) +++ gcc/tree-ssa-forwprop.c (working copy) @@ -1789,8 +1789,11 @@ defcodefor_name (arg1, &def1_code, &def1_arg1, &def1_arg2); defcodefor_name (arg2, &def2_code, &def2_arg1, &def2_arg2); - /* Try to fold (type) X op CST -> (type) (X op ((type-x) CST)). */ + /* Try to fold (type) X op CST -> (type) (X op ((type-x) CST)). + Do that only in non-first forwprop passes as otherwise x-or pattern + may be not recognized. */ if (TREE_CODE (arg2) == INTEGER_CST + && !first_pass_instance && CONVERT_EXPR_CODE_P (def1_code) && INTEGRAL_TYPE_P (TREE_TYPE (def1_arg1)) && int_fits_type_p (arg2, TREE_TYPE (def1_arg1))) Index: gcc/testsuite/gcc.dg/pr56175.c =================================================================== --- gcc/testsuite/gcc.dg/pr56175.c (revision 0) +++ gcc/testsuite/gcc.dg/pr56175.c (working copy) @@ -0,0 +1,30 @@ +/* PR tree-optimization/56175 */ +/* { dg-do compile } */ +/* { dg-options "-O2 -ftree-loop-if-convert" } */ +/* { dg-final { scan-assembler "xorl" { target i?86-*-* x86_64-*-* } } } " */ + +typedef unsigned short u16; +typedef unsigned char u8; + +u16 foo(u8 x, u16 y ) +{ + u8 i,t,c; + for (i = 0; i < 8; i++) + { + t = (u8)((x & 1) ^ ((u8)y & 1)); + x >>= 1; + if (t == 1) + { + y ^= 0x4002; + c = 1; + } + else + c = 0; + y >>= 1; + if (c) + y |= 0x8000; + else + y &= 0x7fff; + } + return y; +}