https://bugs.llvm.org/show_bug.cgi?id=50197
Bug ID: 50197
Summary: 128 bit arithmetic --- inefficient logic test
Product: new-bugs
Version: trunk
Hardware: PC
OS: All
Status: NEW
Severity: enhancement
Priority: P
Component: new bugs
Assignee: unassignedb...@nondot.org
Reporter: z...@smallinteger.com
CC: htmldevelo...@gmail.com, llvm-bugs@lists.llvm.org
Created attachment 24821
--> https://bugs.llvm.org/attachment.cgi?id=24821&action=edit
Sample code
See attached code, compiled with -O2. The condition inside the while () test
is unnecessarily evaluated with a 128 bit shift instruction,
square: # @square
mov rax, rdi
.LBB0_1: # =>This Inner Loop Header: Depth=1
add rax, 1
adc rsi, 0
mov rcx, rsi
shld rcx, rax, 4
mov rdx, rsi
shr rdx, 60
or rdx, rcx
jne .LBB0_1
ret
even though a 64 bit shift instruction suffices. However, changing || to | in
the logic condition yields the more efficient code below.
square: # @square
mov rax, rdi
.LBB0_1: # =>This Inner Loop Header: Depth=1
add rax, 1
adc rsi, 0
mov rcx, rax
shr rcx, 60
or rcx, rsi
jne .LBB0_1
ret
Found with clang-10 on Ubuntu 20.04 LTS, verified for clang 10, 11, and trunk
using godbolt. Note that gcc -O2 handles both of these cases emitting the more
efficient code.
--
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs