llvm_21: backport patch for selectiondag freeze condition miscompile

Several LLVM versions have a bug in SelectionDAG that causes
miscompilations around conditional poisions. This was exposed due to
Rust 1.97.0 exercising the involved code path heavily and generating
segfaulting code, but the bug existed beforehand as well. The patch was
made to LLVM 23, but the tests have many conflicts, so this is a manual
backport. This backport was made by:

- applying the code change to `llvm/lib`
- hand-updating `test/CodeGen/Mips/cmov.ll` with the same diff as the PR
- updating the rest with `utils/update_llc_test_checks.py` from the LLVM
  source tree, and verifying the diff against the one in the PR.

The last step made this a rather large and gnarly patch, but it's mostly
mechanical.

Rust issue: https://github.com/rust-lang/rust/issues/159035
LLVM issue: https://github.com/llvm/llvm-project/issues/208611
LLVM PR: https://github.com/llvm/llvm-project/pull/208683
This commit is contained in:
whispers
2026-07-14 22:43:00 -04:00
parent 4169bd4063
commit f8a025c964
2 changed files with 3988 additions and 1 deletions

View File

@@ -222,7 +222,19 @@ stdenv.mkDerivation (
hash = "sha256-3hkbYPUVRAtWpo5qBmc2jLZLivURMx8T0GQomvNZesc=";
stripLen = 1;
}
);
)
++ lib.optionals (lib.versions.major release_version == "21") [
# Several LLVM versions have a bug in SelectionDAG that causes
# miscompilations around conditional poisions. This was exposed due to
# Rust 1.97.0 exercising the involved code path heavily and generating
# segfaulting code. The patch was made to LLVM 23, but the tests have
# many conflicts, so we vendor a version-specific modified version.
#
# Rust issue: https://github.com/rust-lang/rust/issues/159035
# LLVM issue: https://github.com/llvm/llvm-project/issues/208611
# LLVM PR: https://github.com/llvm/llvm-project/pull/208683
(getVersionFile "llvm/sdag-freeze-condition-in-select-of-load-fold.patch")
];
nativeBuildInputs = [
cmake