[llvm] [RISCV][GISel] Added GISelPRedicateCodes to LeadingOnes*Mask (PR #119886)
Sam Elliott via llvm-commits
llvm-commits at lists.llvm.org
Fri Dec 13 10:19:51 PST 2024
================
@@ -493,7 +493,15 @@ def LeadingOnesMask : PatLeaf<(imm), [{
if (!N->hasOneUse())
return false;
return !isInt<32>(N->getSExtValue()) && isMask_64(~N->getSExtValue());
-}], TrailingZeros>;
+}], TrailingZeros> {
+ let GISelPredicateCode = [{
+ if (!MRI.hasOneNonDBGUse(MI.getOperand(0).getReg()))
+ return false;
+ const auto &MO = MI.getOperand(1);
----------------
lenary wrote:
> GISel uses MachineIR where defs and uses are "operands". For G_CONSTANT, operand 0 is the def and operand 1 is the source.
Ok, so `MI` is the instruction that "defines" the vreg being used in the instruction being matched. And we have to look at its operands because immediates are not stored inline (except in G_CONSTANT). That makes sense.
> The (imm) in the PatLeaf should guarantee this is only called for G_CONSTANT
I took a look through the generated match table code, and I couldn't find what guaranteed this, which is part of where my confusion came from.
The handler for `GIM_CheckCxxInsnPredicate` doesn't check the opcode before calling `testMIPredicate_MI` (which contains this C++), and if you look at e.g. `MatchTable0` in `RISCVGenGlobalISel.inc`, there's not always a `GIM_CheckOpcode` with `G_CONSTANT` before `GIM_CheckCxxInsnPredicate`.
https://github.com/llvm/llvm-project/pull/119886
More information about the llvm-commits
mailing list