llvm/llvm-project

[X86] Failure to reduce extended i64 add/sub/mul arithmetic to i32 with known zeros in the upper 32-bits

Open

#142.308 geöffnet am 1. Juni 2025

Auf GitHub ansehen
 (13 Kommentare) (0 Reaktionen) (1 zugewiesene Person)C++ (10.782 Forks)batch import
backend:X86good first issuemissed-optimization

Repository-Metriken

Stars
 (26.378 Stars)
PR-Merge-Metriken
 (Durchschn. Merge 1T 2h) (1.000 gemergte PRs in 30 T)

Beschreibung

https://c.godbolt.org/z/3Gv4rPEGq

As noted on #141360 - x86 i64 add/sub/mul arithmetic is not reduced to i32 arithmetic when the upper 32-bits are known to be zero (and can be implicitly zero-extended). We do appear to do this for logic and shift instructions.

On recent CPU targets, ADD/SUB i64 is usually just as cheap as i32 equivalents but MUL can often still benefit, and there's potential for shorter instruction encodings for all of them.

We can either handle this with combineAdd/Sub/Mul in X86ISelLowering.cpp or we can wait until X86ISelDAGToDAG.cpp

Contributor Guide