[llvm] [RISCV] Commute True in foldVMergeToMask (PR #156499)
Craig Topper via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 2 11:49:19 PDT 2025
================
@@ -745,12 +745,24 @@ bool RISCVVectorPeephole::foldVMergeToMask(MachineInstr &MI) const {
if (PassthruReg && !isKnownSameDefs(PassthruReg, FalseReg))
return false;
+ std::optional<std::pair<unsigned, unsigned>> NeedsCommute;
+
// If True has a passthru operand then it needs to be the same as vmerge's
// False, since False will be used for the result's passthru operand.
Register TruePassthru = True.getOperand(True.getNumExplicitDefs()).getReg();
if (RISCVII::isFirstDefTiedToFirstUse(True.getDesc()) && TruePassthru &&
- !isKnownSameDefs(TruePassthru, FalseReg))
- return false;
+ !isKnownSameDefs(TruePassthru, FalseReg)) {
+ // If True's passthru != False, check if it uses False in another operand
+ // and try to commute it.
+ int OtherIdx = True.findRegisterUseOperandIdx(FalseReg, TRI);
+ if (OtherIdx == -1)
+ return false;
+ unsigned OpIdx1 = OtherIdx;
+ unsigned OpIdx2 = TargetInstrInfo::CommuteAnyOperandIndex;
----------------
topperc wrote:
Shouldn't OpIdx2 be the index of the passthru operand?
https://github.com/llvm/llvm-project/pull/156499
More information about the llvm-commits
mailing list