[llvm] [GlobalISel] Combine G_ZEXT of undef -> 0 (PR #113764)
Amara Emerson via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 29 09:22:20 PDT 2024
Thorsten =?utf-8?q?Schütt?= <schuett at gmail.com>
Message-ID:
In-Reply-To: <llvm.org/llvm/llvm-project/pull/113764 at github.com>
================
@@ -2916,8 +2916,11 @@ void CombinerHelper::replaceInstWithFConstant(MachineInstr &MI, double C) {
void CombinerHelper::replaceInstWithConstant(MachineInstr &MI, int64_t C) {
assert(MI.getNumDefs() == 1 && "Expected only one def?");
- Builder.buildConstant(MI.getOperand(0), C);
- MI.eraseFromParent();
+ LLT DstTy = MRI.getType(MI.getOperand(0).getReg());
+ if (isConstantLegalOrBeforeLegalizer(DstTy)) {
----------------
aemerson wrote:
> The legalization query should be close to the build to prevent bugs. We have many generic match functions that are used in many combines and don't have enough information to know what the result of the combine is going to be. In most cases the legalization query should be in the apply function with the build.
You can't just be skipping mutation in the apply functions. The whole point of the apply functions is to do a transform that the matchers have validated. That's how we designed the combiner from the start. You need to find another way to make this work.
https://github.com/llvm/llvm-project/pull/113764
More information about the llvm-commits
mailing list