← board

--xtensa-cpu=lx6 is a no-op, and the LX6 does have a divider

What was asked and what is true

frankd-90 saw byte-identical objects and quos/rems still emitted. The first half reproduces. The second half does not: nothing emits quos/rems.

  1. The premise is false. The ESP32 classic LX6 has the divide option:

    $ xtensa-esp32-elf-gcc -O2 -c d.c     # int f(int a,int b){return a/b;}
    3:  d22230    quos  a2, a2, a3
    b:  f22230    rems  a2, a2, a3
    $ printf '\tquos a2,a2,a3\n' | xtensa-esp32-elf-as     # accepted
    

    Four places in the tree said otherwise (compiler.pas at the flag parse, defs.inc on XtensaSoftDivide, pasparser_prog.inc at the helper registration, builtinheap.pas above the helpers). All four are corrected in the same commit as this ticket, since the measurement is cheap to redo and the claim is load-bearing for the flag's existence.

    The tree already contradicted itself: defs.inc's XtensaSoftMulHigh comment records that all eight qemu-xtensa cores "DO have the divide option", which cannot hold for a part that lacks one.

  2. The flag changes nothing. div32.pas — b := p^ from an arbitrary address so the divisor cannot be folded, operands and results all 32-bit Integer, results consumed:

    build quos quou rems remu object sha12
    --target=esp32 0 0 0 0 53ccaef80f8e
    --target=esp32 --xtensa-cpu=lx6 0 0 0 0 53ccaef80f8e

    Byte-identical, and __pxx_divsi3/__pxx_modsi3 are absent from the symbol table in both, although pasparser_prog.inc registers them under the flag.

  3. No xtensa target emits a hardware divide. Same program, same search:

    target div+mod cost quos/quou/rems/remu
    esp32 384 B 0
    esp32s2 384 B 0
    esp32s3 384 B 0
    esp32c3 (riscv32, control) 368 B n/a

    esp32s3 is the LX7 part whose quos/rems the default is documented to keep, and it emits none either. So ir_codegen_xtensa.inc:3161-3176 — the only four sites that read XtensaSoftDivide, and the only four that call xtensa_quos/quou/rems/remu — appear unreachable, and the flag is dead because the code it toggles is dead.

What is NOT established

Where div/mod actually get lowered. The 384 B says something substantial is emitted, but I did not identify it, and I am not going to guess in a ticket. Candidates not ruled out:

Instrument notes, because three instruments lied here

Worth reading before redoing any of this — I drew a wrong conclusion from each of the first three before validating them.

Decision needed

Three options, in my order of preference:

  1. Find the real lowering and emit quos/rems on the parts that have them (all of esp32/s2/s3, and the LX6 included). Integer division on ESP then costs one instruction instead of whatever the 384 B is. This is the only option that turns the finding into a win.
  2. Delete the flags and the helpers. Nothing reaches them, the part they were written for does not need them, and dead capability flags invite exactly the wrong conclusion the next person draws.
  3. Document them as no-ops and leave them. Cheapest, and what the corrected comments currently do.

Not urgent: results are correct today, so this is speed and dead code, not miscompilation.