--- /dev/null
+/* { dg-do compile } */
+/* PR tree-optimization/122629 */
+
+/* factor_out_operators was factoring out BIT_FIELD_REF and BIT_INSERT_EXPR,
+ both which requires constant operands so it would not valid to factor. */
+
+typedef int ix4 __attribute__((vector_size(4*sizeof(int))));
+
+int f(ix4 *a, int l, int *b)
+{
+ for (int i =0 ;i < l; i++)
+ {
+ int t;
+ ix4 tt = a[i];
+ if(*b) t = tt[1]; else t = tt[0];
+ *b = t;
+ }
+}
+
+int g(ix4 *a, int l, int *b)
+{
+ for (int i =0 ;i < l; i++)
+ {
+ ix4 tt = a[i];
+ if(*b) tt[1] = 1; else tt[0] = 1;
+ *a = tt;
+ }
+}
--- /dev/null
+/* { dg-do compile } */
+/* PR tree-optimization/122629 */
+
+typedef int ix4 __attribute__((vector_size(4*sizeof(int))));
+
+int f(ix4 *a, int l, int *b, ix4 *c)
+{
+ for (int i =0 ;i < l; i++)
+ {
+ int t;
+ ix4 tt = a[i];
+ ix4 tt1 = c[i];
+ if(*b) t = tt1[0]; else t = tt[0];
+ *b = t;
+ }
+}
+
+int g(ix4 *a, int l, int *b, ix4 *c)
+{
+ for (int i =0 ;i < l; i++)
+ {
+ ix4 tt = a[i];
+ ix4 tt1 = c[i];
+ if(*b) {
+ tt = tt1;
+ tt[0] = 1;
+ } else {
+ tt[0] = 1;
+ }
+ a[i] = tt;
+ }
+}
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-ifcvt-details" } */
+/* PR tree-optimization/122629 */
+
+typedef int ix4 __attribute__((vector_size(4*sizeof(int))));
+
+int f(ix4 *a, int l, int *b, ix4 *c)
+{
+ for (int i =0 ;i < l; i++)
+ {
+ int t;
+ ix4 tt = a[i];
+ ix4 tt1 = c[i];
+ if(*b) t = tt1[0]; else t = tt[0];
+ *b = t;
+ }
+}
+
+int g(ix4 *a, int l, int *b, ix4 *c)
+{
+ for (int i =0 ;i < l; i++)
+ {
+ ix4 tt = a[i];
+ ix4 tt1 = c[i];
+ if(*b) {
+ tt = tt1;
+ tt[0] = 1;
+ } else {
+ tt[0] = 1;
+ }
+ a[i] = tt;
+ }
+}
+
+/* Make sure BIT_INSERT_EXPR/BIT_FIELD_REF is still factored out for the case if operand 0 is different. */
+/* { dg-final { scan-tree-dump-times "changed to factor operation out from" 2 "ifcvt" } } */
if (opnum == -1)
return;
+ /* BIT_FIELD_REF and BIT_INSERT_EXPR can't be factored out for non-0 operands
+ as the other operands require constants. */
+ if ((arg1_op.code == BIT_FIELD_REF
+ || arg1_op.code == BIT_INSERT_EXPR)
+ && opnum != 0)
+ return;
+
+
if (!types_compatible_p (TREE_TYPE (new_arg0), TREE_TYPE (new_arg1)))
return;
tree new_res = make_ssa_name (TREE_TYPE (new_arg0), NULL);