aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/CodeGen/MachineSink.cpp
diff options
context:
space:
mode:
authorCraig Topper <craig.topper@sifive.com>2024-07-17 13:06:58 -0700
committerGitHub <noreply@github.com>2024-07-17 13:06:58 -0700
commit495d3ea989d4e97ce77ee73d6b35b171a7346019 (patch)
treecb85cdd9ac5b36bceb0b3c93ca5b02645c2e231e /llvm/lib/CodeGen/MachineSink.cpp
parent8044a863518166db1a1e05df5c76e26d53dbbcb9 (diff)
downloadllvm-495d3ea989d4e97ce77ee73d6b35b171a7346019.zip
llvm-495d3ea989d4e97ce77ee73d6b35b171a7346019.tar.gz
llvm-495d3ea989d4e97ce77ee73d6b35b171a7346019.tar.bz2
[MachineSink][RISCV] Only call isConstantPhysReg or isIgnorableUse for uses. (#99363)
The included test case contains X0 as a def register. X0 is considered a constant register when it is a use. When its a def, it means to throw away the result value. If we treat it as a constant register here, we will execute the continue and not assign `DefReg` to any register. This will cause a crash when trying to get the register class for `DefReg` after the loop. By only checking isConstantPhysReg for uses, we will reach the `return false` a little further down and stop processing this instruction.
Diffstat (limited to 'llvm/lib/CodeGen/MachineSink.cpp')
-rw-r--r--llvm/lib/CodeGen/MachineSink.cpp2
1 files changed, 1 insertions, 1 deletions
diff --git a/llvm/lib/CodeGen/MachineSink.cpp b/llvm/lib/CodeGen/MachineSink.cpp
index d782c8b..4b3ff57 100644
--- a/llvm/lib/CodeGen/MachineSink.cpp
+++ b/llvm/lib/CodeGen/MachineSink.cpp
@@ -417,7 +417,7 @@ bool MachineSinking::PerformSinkAndFold(MachineInstr &MI,
continue;
}
- if (Reg.isPhysical() &&
+ if (Reg.isPhysical() && MO.isUse() &&
(MRI->isConstantPhysReg(Reg) || TII->isIgnorableUse(MO)))
continue;