A question of Sparc assembly generated by llc


There are some generated Sparc assembly code like this:

main: ! @main
! BB#0:
  save %sp, -112, %sp
  sethi 0, %l0
  or %g0, 5, %l1
  st %l0, [%fp+-4]
  st %l1, [%fp+-8]
  st %l1, [%fp+-12]
  sethi %hi(.L.str), %l1
  ld [%fp+-8], %o1
  add %l1, %lo(.L.str), %l1
  or %g0, %l1, %o0
  call printf
  ld [%fp+-12], %o2
  ld [%fp+-8], %l2
  sethi %hi(.L.strQ521), %l3
  add %l3, %lo(.L.strQ521), %o0
  or %g0, %l2, %o1
        call MY_FUNCTION
        or %g0, 1, %i0
       (subcc %l1, 0, %l1 ! This line is added by me. It was not there)
        bne .LBB0_2
! BB#1:
  subcc %l2, 0, %l2
  or %g0, %l0, %i0

I am not an expert on Sparc assembly, but I read from somewhere that
branching instructions are set by the statues flags. The first 'bne'
statement appeared before any subcc or any other cc opcodes. The code is
problematic so I added the line in the brackets based on what I think it
should be doing and it appeared to be working correctly.

Is the standalone 'bne' instruction intentional? There are some integer
condition code in MY_FUNCTION but I thought the iCC flags will be saved
before the 'call' statement and restored after the 'call' statement. Is it

By the way, there are 'save %sp, -96, %sp', 'restore %g0, %g0, %g0' and
'retl' statements in MY_FUNCTION.



Hi Chris,

  'subcc' instruction is necessary for 'bne' to work correctly.
Conditional flags (ICC, FCC) are clobbered by Call instructions in
Sparc. They are not saved and restored around call instructions.
  What is the version of LLVM that you used? If this code is generated
by recent LLVM, please file a bug report with a testcase.