Hi!
First, a *big* thanks to Mark Yoder, who kindly put a whole lot of information together to help me figure this out.
I'm attempting to using the BBB to make a simple motor controller and will use the PRU's to do the critical timing
events.  To demonstrate a baby step, I decided to play around with an ultrasonic detector to prove I could generate
timed pulses, and also time an incoming pulse.  I started using Mark's PruCookbook set up.  I found that using
the -O 2 flag for clpru, the compiler would *delete* certain looping code.  Removing the flag would run the code
properly.  It took a while to figure out what was happening since I'm not an expert in assembly, but looking at
the .lst file and using prudebug and single stepping showed me what the problem was.
Details:
while (1)
    {
      runState = pru0Dram[0];Â
      if (runState == 0)
      {
        __R30 &= ~gpio;     // Set the GPIO pin to 0, this should be a 10 us pulse
        continue;
      }
      onTime = pru0Dram[1];Â
      __R30 |= gpio;
 >>>      while(1)
      {
        if (counter > onTime)
        {
          __R30 &= ~gpio;     // Set the GPIO pin to 0, this should be a 10 us pulse
          break;
        }
        counter += 1;
      }
      inputState = 0;
without the -O 2 flag, the compiler generates the following assembly code.
  259;----------------------------------------------------------------------
   260; 54 | __R30 |= gpio;                            Â
   261;----------------------------------------------------------------------
   262 0000007c 000000F1002281     LBBO   &r1, r2, 0, 4     ; [ALU_PRU] |54| gpio
   263 00000080 00000012E1FEFE     OR    r30, r30, r1     ; [ALU_PRU] |54|Â
   264    .dwpsn file "pruUltraSonic2.c",line 55,column 19,is_stmt,isa 0
   265;----------------------------------------------------------------------
   266; 55 | while(1)                               Â
   267;----------------------------------------------------------------------
   268;* --------------------------------------------------------------------------*
   269;*  BEGIN LOOP ||$C$L3||
   270;*
   271;*  Loop source line        : 55
   272;*  Loop closing brace source line : 63
   273;*  Known Minimum Trip Count    : 1
   274;*  Known Maximum Trip Count    : 4294967295
   275;*  Known Max Trip Count Factor   : 1
PRU Assembler Unix v2.3.1 Sat Dec 1 17:26:17 2018
Tools Copyright (c) 2012-2017 Texas Instruments Incorporated
/tmp/pru0-gen/pruUltraSonic2.asm                   PAGE  6
   276;* --------------------------------------------------------------------------*
   277 00000084         ||$C$L3||:  Â
   278    .dwpsn file "pruUltraSonic2.c",line 57,column 17,is_stmt,isa 0
   279;----------------------------------------------------------------------
   280; 57 | if (counter > onTime)                         Â
   281;----------------------------------------------------------------------
   282 00000084 000000F1142280     LBBO   &r0, r2, 20, 4    ; [ALU_PRU] |57| counter
   283 00000088 00000058E0EE04     QBLE   ||$C$L4||, r14, r0  ; [ALU_PRU] |57|Â
   284;* --------------------------------------------------------------------------*
   285    .dwpsn file "pruUltraSonic2.c",line 59,column 21,is_stmt,isa 0
   286;----------------------------------------------------------------------
   287; 59 | __R30 &= ~gpio;     // Set the GPIO pin to 0, this should be a 10 u
   288;   | s pulse                                Â
   289;----------------------------------------------------------------------
   290 0000008c 0000001600E1E0     NOT    r0, r1        ; [ALU_PRU] |59|Â
   291 00000090 00000010E0FEFE     AND    r30, r30, r0     ; [ALU_PRU] |59|Â
   292    .dwpsn file "pruUltraSonic2.c",line 60,column 21,is_stmt,isa 0
   293;----------------------------------------------------------------------
   294; 60 | break;                                Â
   295;----------------------------------------------------------------------
   296 00000094 00000021000000!     JMP    ||$C$L5||       ; [ALU_PRU] |60|Â
   297;* --------------------------------------------------------------------------*
   298 00000098         ||$C$L4||:  Â
   299    .dwpsn file "pruUltraSonic2.c",line 62,column 17,is_stmt,isa 0
   300;----------------------------------------------------------------------
   301; 62 | counter += 1;                             Â
   302;----------------------------------------------------------------------
   303 00000098 0000000101E0E0     ADD    r0, r0, 0x01     ; [ALU_PRU] |62|Â
   304 0000009c 000000E1142280     SBBO   &r0, r2, 20, 4    ; [ALU_PRU] |62| counter
   305    .dwpsn file "pruUltraSonic2.c",line 55,column 19,is_stmt,isa 0
   306 000000a0 00000021000000!     JMP    ||$C$L3||       ; [ALU_PRU] |55|Â
With the -O2 flag present, the compiler generates
 187; 54 | __R30 |= gpio;                            Â
   188; 55 | while(1)                               Â
   189; 57 |   if (counter > onTime)                       Â
   190;----------------------------------------------------------------------
   191 00000020 0000001F00FEFE     SET    r30, r30, 0x00000000 ; [ALU_PRU] |54|Â
   192    .dwpsn file "pruUltraSonic2.c",line 59,column 21,is_stmt,isa 0
   193;----------------------------------------------------------------------
   194; 59 | __R30 &= ~gpio;     // Set the GPIO pin to 0, this should be a 10 u
   195;   | s pulse                                Â
   196; 60 | break;                                Â
   197; 62 | counter += 1;                             Â
   198; 65 | inputState = 0;                            Â
   199; 66 | didSeeHigh = 0;                            Â
   200; 67 | timerWhenHigh = 0;                          Â
   201; 68 | counter = 0;                             Â
   202;----------------------------------------------------------------------
   203 00000024 0000001D00FEFE     CLR    r30, r30, 0x00000000 ; [ALU_PRU] |59|Â
   204    .dwpsn file "pruUltraSonic2.c",line 69,column 13,is_stmt,isa 0
   205;----------------------------------------------------------------------
Notice that there is No looping code.  It sets the R30 (gpio) and then imediately clears CLR R30.
This really took a while to figure out what was happening.   I downloaded the newest compiler version from TI and
the issue remains...   I haven't tried other levels of optimization to find out if the issue still exists.
Bill Bitner