https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98673
--- Comment #5 from jojo <rjiejie at me dot com> --- Sorry for late :) Please test with following c case: long YTableLookup (long xValue, long xEntries, const long *xAxis, const long *yTable ) { int i ; long xDelta ; long outValue ; for (i=0; i<(xEntries - 1); i++) { if ((xValue < xAxis[i + 1]) && (xValue >= xAxis[i])) break ; } if (i == (xEntries - 1)) xValue = xAxis[i] ; xDelta = (long) ((xValue - xAxis[i]) * 1000) / (xAxis[i + 1] - xAxis[i]); outValue = (long) ((((1000 - xDelta) * (long) yTable[i]) / 1000) + ((xDelta * (long) yTable[i+1]) / 1000)) ; return outValue ; } risc-v cc1 option: -O2 -march=rv32gc -mabi=ilp32d ================================================= YTableLookup: addi a1,a1,-1 ble a1,zero,.L2 li a7,4 li a4,0 sub a7,a7,a2 j .L5 .L6: mv a4,a5 .L5: lw a6,4(a2) addi a5,a4,1 add t1,a7,a2 ble a6,a0,.L3 lw t3,0(a2) slli t4,a4,2 ble t3,a0,.L9 .L3: addi a2,a2,4 bne a1,a5,.L6 addi a4,a4,2 slli t1,a4,2 addi t4,t1,-4 add t4,a3,t4 li a1,0 li a5,1000 .L4: or x86 cc1 option: -O2 -march=i386 ================================== YTableLookup: .LFB0: pushl %ebp .LCFI0: pushl %edi .LCFI1: pushl %esi .LCFI2: pushl %ebx .LCFI3: pushl %ecx .LCFI4: movl 24(%esp), %esi movl 32(%esp), %edi movl 28(%esp), %eax decl %eax testl %eax, %eax jle .L2 movl $4, %ecx xorl %edx, %edx jmp .L5 .align 4 .L6: movl %ebx, %edx .L5: movl (%edi,%ecx), %ebx cmpl %esi, %ebx jle .L3 leal -4(%ecx), %ebp movl %ebp, (%esp) movl (%edi,%edx,4), %ebp cmpl %esi, %ebp jle .L10 .L3: leal 1(%edx), %ebx addl $4, %ecx cmpl %ebx, %eax jne .L6 leal 8(,%edx,4), %ecx movl 36(%esp), %eax leal -4(%eax,%ecx), %esi xorl %eax, %eax movl $1000, %ebx .L4: Please check the redundancy instruction 'mov' at .L6: