[llvm] [GlobalIsel] Combine selects with constants (PR #76089)
Amara Emerson via llvm-commits
llvm-commits at lists.llvm.org
Tue Jan 2 00:21:43 PST 2024
Thorsten =?utf-8?q?Schütt?= <schuett at gmail.com>
Message-ID:
In-Reply-To: <llvm.org/llvm/llvm-project/pull/76089 at github.com>
================
@@ -6352,16 +6352,22 @@ bool CombinerHelper::tryFoldSelectOfConstants(GSelect *Select,
LLT CondTy = MRI.getType(Select->getCondReg());
LLT TrueTy = MRI.getType(Select->getTrueReg());
- // Either both are scalars or both are vectors.
- std::optional<APInt> TrueOpt = getConstantOrConstantSplatVector(True);
- std::optional<APInt> FalseOpt = getConstantOrConstantSplatVector(False);
+ // Only do this before legalization to avoid conflicting with target-specific
+ // transforms in the other direction.
+ if (CondTy != LLT::scalar(1))
+ return false;
----------------
aemerson wrote:
To implement your comment this check only works for AArch64, you should use `isPreLegalize()` instead.
However I think you actually want what your code does here, i.e. the `s1` check. So probably rewrite the comment to remove the part about before-legalization. For non-s1 types you might need to care about getBooleanContents() etc so easier to do it for s1 only.
https://github.com/llvm/llvm-project/pull/76089
More information about the llvm-commits
mailing list