[llvm] [RISCV] Fix a correctness issue in optimizeCondBranch. Prevent optimizing compare with x0. NFC (PR #145440)
Philip Reames via llvm-commits
llvm-commits at lists.llvm.org
Tue Jun 24 08:02:03 PDT 2025
================
@@ -1449,11 +1449,14 @@ bool RISCVInstrInfo::optimizeCondBranch(MachineInstr &MI) const {
return Register();
};
- if (isFromLoadImm(MRI, LHS, C0) && MRI.hasOneUse(LHS.getReg())) {
+ if (isFromLoadImm(MRI, LHS, C0) && LHS.getReg().isVirtual() &&
+ MRI.hasOneUse(LHS.getReg())) {
+ assert(isInt<12>(C0) && "Unexpected immediate");
// Might be case 1.
- // Signed integer overflow is UB. (UINT64_MAX is bigger so we don't need
- // to worry about unsigned overflow here)
- if (C0 < INT64_MAX)
+ // Don't change 0 to -1 since we can use x0.
----------------
preames wrote:
This comment seems off? We'd convert it to +1 wouldn't we?
https://github.com/llvm/llvm-project/pull/145440
More information about the llvm-commits
mailing list