[llvm] [TargetLowering] Deduplicate choosing InlineAsm constraint between ISels (PR #67057)

Nick Desaulniers via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 21 14:37:34 PDT 2023


================
@@ -5701,13 +5702,19 @@ TargetLowering::ParseConstraints(const DataLayout &DL,
   return ConstraintOperands;
 }
 
-/// Return an integer indicating how general CT is.
-static unsigned getConstraintGenerality(TargetLowering::ConstraintType CT) {
+/// Return a number indicating our preference for chosing a type of constraint
+/// over another, for the purpose of sorting them. Immediates are almost always
+/// preferrable (when they can be emitted).
+/// FIXME: We should prefer registers over memory but doing so may lead to
+/// unrecoverable register exhaustion later.
+/// https://github.com/llvm/llvm-project/issues/20571
+static unsigned getConstraintPiority(TargetLowering::ConstraintType CT) {
   switch (CT) {
-  case TargetLowering::C_Immediate:
-  case TargetLowering::C_Other:
   case TargetLowering::C_Unknown:
     return 0;
+  case TargetLowering::C_Immediate:
+  case TargetLowering::C_Other:
+    return 4;
----------------
nickdesaulniers wrote:

Also, this change intentionally //increases// the priority for these 2; previously `chooseConstraint` would stop as soon as it hit one that could be lowered.  This is //conceptually// the same thing as having a higher priority.

https://github.com/llvm/llvm-project/pull/67057


More information about the llvm-commits mailing list