https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63224

--- Comment #8 from Sebastian Huber <sebastian.hu...@embedded-brains.de> ---
Actually the for loop is not necessary.

int bar(int s, int *a)
{
    int c;
    int r;

    r = s != 0 && (c = a[s]);

    if (s == 2 && c == 0) {
    } else if (s != 0) {
        return 0;
    }

    return r;
}

cp test.c Os.c
cp test.c O2.c
arm-rtems4.11-gcc -Wfatal-errors -Wall -Os -S Os.c -o Os.s
-fdump-tree-all-all-lineno
Os.c: In function 'bar':
Os.c:8:18: warning: 'c' may be used uninitialized in this function
[-Wmaybe-uninitialized]
  if (s == 2 && c == 0) {
                  ^
arm-rtems4.11-gcc -Wfatal-errors -Wall -O2 -S O2.c -o O2.s
-fdump-tree-all-all-lineno

diff -u O*c*uni*
--- O2.c.140t.uninit1   2014-09-12 09:29:10.627991057 +0200
+++ Os.c.140t.uninit1   2014-09-12 09:29:10.574991191 +0200
@@ -5,6 +5,9 @@
 Pass statistics:
 ----------------

+[WORKLIST]: add to initial list: c_1 = PHI <c_5(D)(7), c_11(3)>
+[CHECK]: examining phi: c_1 = PHI <c_5(D)(7), c_11(3)>
+[CHECK]: Found unguarded use: _13 = c_1 == 0;

 Pass statistics:
 ----------------
@@ -13,13 +16,97 @@
 {
   intD.3 rD.4078;
   intD.3 cD.4077;
+  intD.3 _3;
+  unsigned intD.6 s.1_6;
+  unsigned intD.6 _7;
+  intD.3 * _9;
+  _BoolD.1375 _12;
+  _BoolD.1375 _13;
+  _BoolD.1375 _14;
+  _BoolD.1375 _16;
+  _BoolD.1375 _18;

 ;;   basic block 2, loop depth 0, count 0, freq 10000, maybe hot
-;;    prev block 0, next block 1, flags: (NEW, REACHABLE)
+;;    prev block 0, next block 7, flags: (NEW, REACHABLE)
 ;;    pred:       ENTRY [100.0%]  (FALLTHRU,EXECUTABLE)
+;;   starting at line 6
+  [Os.c : 6:13] if (s_4(D) != 0)
+    goto <bb 3>;
+  else
+    goto <bb 7>;
+;;    succ:       3 [50.0%]  (TRUE_VALUE,EXECUTABLE)
+;;                7 [50.0%]  (FALSE_VALUE,EXECUTABLE)
+
+;;   basic block 7, loop depth 0, count 0, freq 5000, maybe hot
+;;    prev block 2, next block 3, flags: (NEW)
+;;    pred:       2 [50.0%]  (FALSE_VALUE,EXECUTABLE)
+;; 
+  goto <bb 4>;
+;;    succ:       4 [100.0%]  (FALLTHRU)
+
+;;   basic block 3, loop depth 0, count 0, freq 5000, maybe hot
+;;    prev block 7, next block 4, flags: (NEW, REACHABLE)
+;;    pred:       2 [50.0%]  (TRUE_VALUE,EXECUTABLE)
+;;   starting at line 6, discriminator 1
+  [Os.c : 6:22] # RANGE [1, 4294967295]
+  s.1_6 = (unsigned intD.6) s_4(D);
+  [Os.c : 6:22] # RANGE [0, 4294967295] NONZERO 0x000000000fffffffc
+  _7 = s.1_6 * 4;
+  [Os.c : 6:22] # PT = nonlocal 
+  _9 = a_8(D) + _7;
+  [Os.c : 6:19] # VUSE <.MEM_10(D)>
+  c_11 = [Os.c : 6] *_9;
+  [Os.c : 6:13] # RANGE [0, 1]
+  _16 = c_11 != 0;
+  [Os.c : 6:13] # RANGE [0, 1] NONZERO 0x00000000000000001
+  r_19 = (intD.3) _16;
+;;    succ:       4 [100.0%]  (FALLTHRU,EXECUTABLE)
+
+;;   basic block 4, loop depth 0, count 0, freq 10000, maybe hot
+;;    prev block 3, next block 8, flags: (NEW, REACHABLE)
+;;    pred:       7 [100.0%]  (FALLTHRU)
+;;                3 [100.0%]  (FALLTHRU,EXECUTABLE)
+;;   starting at line 8, discriminator 6
+  # c_1 = PHI <c_5(D)(7), c_11(3)>
+  # RANGE [0, 1] NONZERO 0x00000000000000001
+  # r_2 = PHI <[Os.c : 6:13] 0(7), [Os.c : 6:13] r_19(3)>
+  [Os.c : 8:8] # RANGE [0, 1]
+  _12 = s_4(D) == 2;
+  [Os.c : 8:18] # RANGE [0, 1]
+  _13 = c_1 == 0;
+  [Os.c : 8:13] # RANGE [0, 1]
+  _14 = _13 & _12;
+  [Os.c : 9:12] # RANGE [0, 1]
+  _18 = s_4(D) != 0;
+  [Os.c : 9:12] if (_14 < _18)
+    goto <bb 5>;
+  else
+    goto <bb 8>;
+;;    succ:       5 [39.0%]  (TRUE_VALUE,EXECUTABLE)
+;;                8 [61.0%]  (FALSE_VALUE,EXECUTABLE)
+
+;;   basic block 8, loop depth 0, count 0, freq 6100, maybe hot
+;;    prev block 4, next block 5, flags: (NEW)
+;;    pred:       4 [61.0%]  (FALSE_VALUE,EXECUTABLE)
+;; 
+  goto <bb 6>;
+;;    succ:       6 [100.0%]  (FALLTHRU)
+
+;;   basic block 5, loop depth 0, count 0, freq 3900, maybe hot
+;;    prev block 8, next block 6, flags: (NEW)
+;;    pred:       4 [39.0%]  (TRUE_VALUE,EXECUTABLE)
+;; 
+;;    succ:       6 [100.0%]  (FALLTHRU,EXECUTABLE)
+
+;;   basic block 6, loop depth 0, count 0, freq 10000, maybe hot
+;;    prev block 5, next block 1, flags: (NEW, REACHABLE)
+;;    pred:       5 [100.0%]  (FALLTHRU,EXECUTABLE)
+;;                8 [100.0%]  (FALLTHRU)
 ;;   starting at line -1
+  # RANGE [0, 1] NONZERO 0x00000000000000001
+  # _3 = PHI <[Os.c : 10:3] 0(5), [Os.c : 13:2] r_2(8)>
   # VUSE <.MEM_10(D)>
-  return 0;
+  return _3;
 ;;    succ:       EXIT [100.0%] 

 }

Reply via email to