Repository navigation
Conversation
[AUTOMATED] x86 SLEIGH sets an arithmetic instruction's zero flag from the destination register itself, so when the sub that computes a call's length also guards the call (mov rdx,r14; sub rdx,rbx; jbe; ...; call), only_op_use walked from rdx into ZF, the BOOL_OR with CF and the CBRANCH, and rejected the trial: read(fd, buf + got, n - got) printed as (*g_read)(fd,&buf[v2]). AArch64 computes subs into a temporary, sets the flags from it and copies it into x2, and kept the length. kuna_resultflags scores these as AArch64's lifting does. While a CALL or CALLIND argument that an add, sub, inc or dec defines is scored, the walk skips a comparison against a constant that instruction makes, of the value or of the view of it the instruction takes (a 32-bit sub reads edx back out of the rdx heritage rebuilds), when its flag reaches only CBRANCH conditions. A logical op's register is no such evidence: x86 has no flags-only or or xor, and clang tests a bit with mov ecx,eax; and ecx,0x100000; jne. A later instruction's flags (cmp, test), a flag kept as data, a value that goes round into its own instruction again (a loop counter), and a RETURN's trials are scored as before. tests/stages/kuna-resultflags.xml pins the loop, a tail call and its 32-bit twin, with a test, a sete and a loop counter as controls. kuna-calleereadarg.xml Noelo-Lab#8 now pins g3(1,a1,*a0 + 2) for clang's add edx,2, as AArch64's adds already printed; its old control moves to Noelo-Lab#9 on a new k1t that tests x with a separate test instruction.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
On x86, a call loses its last argument when the
suboraddthat computes the argument also sets the flags a branch before the call tests.The AArch64 build (
subs x2,x19,x20; b.ls out; ...; blr x8) prints(fd,&buf[v3],n - v3).resultflags(rdx):ZF = rdx == 0).only_op_usewalks from rdx into ZF, theBOOL_ORwith CF, and theCBRANCH, and rejects the trial. No later argument fills the hole.subsinto a temporary, sets the flags from it, and copies it into x2, so x2's only use is the call.Fix
p4_calls/kuna_resultflags.rs(always on) scores these arguments as AArch64's lifting already does. While aCALLorCALLINDargument is scored, and the value is the result of anadd,sub,incordec, the walk skips a comparison against a constant when both hold:sub edx,ecxreadsedxback out of therdxheritage rebuilds.CBRANCHconditions, through boolean ops, copies, merges andINDIRECTs.These are still uses:
ororxor, so a combined test (xor ecx,0x59; or ecx,eax; jne) writes a register it never reads again. clang also tests a bit withmov ecx,eax; and ecx,0x100000; jne. Admitted, they would give sqlite3'ssqlite3DbMallocRawNN,sqlite3BeginWriteOperationandsqlite3ErrorMsgcalls arguments those functions do not take. The flags-only form ofaddandsubiscmp, so for those a written register is a wanted value.cmpandtest, which write no register.sete).sub rdx,1; jne loopleft in rdx at a call after the loop. AArch64's walk rejects it on the next iteration's temporary.A RETURN's trials are scored as before.
It is a judgement. A hand-written
sub rdx,rbx; jbewhose rdx is dead gives an unknown callee rdx as an argument, as AArch64 already does forsubs. Once the difference is an argument it has two uses, so the guard prints as AArch64 prints it,if (n < v2 || !(n - v2)), where it wasif (n <= v2).Tests
tests/stages/kuna-resultflags.xml, clang -O2 x86-64 bytes:sub rdx,rcx; jne, and its 32-bit twin pass the length. All three fail onmain.main: a loaded value tested by a separatetest, a flag stored bysete, and a hand-assembled countersub rdx,1; jnebefore a tail call. Without the loop check the counter would print as(*a2)(a3,a1,0).kuna-calleereadarg.xml's Perf/actionpool cursor #8 pinnedg3(1)for clang'sg3(1, 0, x), whoseadd edx,2sets the flags itsjereads.g3(1,a1,*a0 + 2), which AArch64'sadds w2,w8,#2already prints for the same source. The gap holds the caller's q because clang leaves esi alone.k1tthat computes x gcc's way (lea edx,[rax+2]; test edx,edx) and printsg3(2)with and without the change.kuna_resultflagscover the flag shapes, the 32-bitPIECEheritage builds, anor, a loop counter, and a RETURN.decompile-all --jobs 1over 1,540 functions of an -O2 x86-64 sqlite3 build changes one:unixMapfile'sosMunmap(pReq + nReuse, pFd->mmapSizeActual - nReuse)gains the length it lacked. It retires 323.66 billion instructions with the change against 323.95 billion onmain, the mean of three runs each, which vary by up to 0.13%.Model:
anthropic/claude-opus-5-5