--- /dev/null
+/* { dg-do run } */
+/* { dg-options "-Os" } */
+
+int b, c, d;
+char e;
+short f;
+const unsigned short **g;
+char h(char k) {
+ if (k)
+ return '0';
+ return 0;
+}
+int l() {
+ b = 0;
+ return 1;
+}
+static short m(unsigned k) {
+ const unsigned short *n[65];
+ g = &n[4];
+ k || l();
+ long a = k;
+ char i = 0;
+ unsigned long j = k;
+ while (j--)
+ *(char *)a++ = i;
+ c = h(d);
+ f = k;
+ return 0;
+}
+int main() {
+ long o = (e < 0) << 5;
+ m(o);
+ if (f != 0)
+ __builtin_abort ();
+ return 0;
+}
basic_block bb_ld = NULL;
basic_block bb_st = NULL;
+ edge exit = single_exit (loop);
if (single_ld)
{
bb_ld = gimple_bb (DR_STMT (single_ld));
if (!dominated_by_p (CDI_DOMINATORS, loop->latch, bb_ld))
return false;
+
+ /* The data reference must also be executed before possibly exiting
+ the loop as otherwise we'd for example unconditionally execute
+ memset (ptr, 0, n) which even with n == 0 implies ptr is non-NULL. */
+ if (bb_ld != loop->header
+ && (!exit
+ || !dominated_by_p (CDI_DOMINATORS, exit->src, bb_ld)))
+ return false;
}
if (single_st)
bb_st = gimple_bb (DR_STMT (single_st));
if (!dominated_by_p (CDI_DOMINATORS, loop->latch, bb_st))
return false;
+
+ /* And before exiting the loop. */
+ if (bb_st != loop->header
+ && (!exit
+ || !dominated_by_p (CDI_DOMINATORS, exit->src, bb_st)))
+ return false;
}
if (single_ld && single_st)