Skip to content

Conversation

@arsenm
Copy link
Contributor

@arsenm arsenm commented Jul 25, 2024

No description provided.

@llvmbot
Copy link
Member

llvmbot commented Jul 25, 2024

@llvm/pr-subscribers-llvm-analysis

@llvm/pr-subscribers-llvm-transforms

Author: Matt Arsenault (arsenm)

Changes

Full diff: https://github.com/llvm/llvm-project/pull/100520.diff

1 Files Affected:

  • (modified) llvm/include/llvm/CodeGen/BasicTTIImpl.h (+29-24)
diff --git a/llvm/include/llvm/CodeGen/BasicTTIImpl.h b/llvm/include/llvm/CodeGen/BasicTTIImpl.h
index 314390aee5085..1a089a3fa9634 100644
--- a/llvm/include/llvm/CodeGen/BasicTTIImpl.h
+++ b/llvm/include/llvm/CodeGen/BasicTTIImpl.h
@@ -2155,30 +2155,11 @@ class BasicTTIImplBase : public TargetTransformInfoImplCRTPBase<T> {
       ISD = ISD::USUBSAT;
       break;
     case Intrinsic::smul_fix:
-    case Intrinsic::umul_fix: {
-      unsigned ExtSize = RetTy->getScalarSizeInBits() * 2;
-      Type *ExtTy = RetTy->getWithNewBitWidth(ExtSize);
-
-      unsigned ExtOp =
-          IID == Intrinsic::smul_fix ? Instruction::SExt : Instruction::ZExt;
-      TTI::CastContextHint CCH = TTI::CastContextHint::None;
-
-      InstructionCost Cost = 0;
-      Cost += 2 * thisT()->getCastInstrCost(ExtOp, ExtTy, RetTy, CCH, CostKind);
-      Cost +=
-          thisT()->getArithmeticInstrCost(Instruction::Mul, ExtTy, CostKind);
-      Cost += 2 * thisT()->getCastInstrCost(Instruction::Trunc, RetTy, ExtTy,
-                                            CCH, CostKind);
-      Cost += thisT()->getArithmeticInstrCost(Instruction::LShr, RetTy,
-                                              CostKind,
-                                              {TTI::OK_AnyValue, TTI::OP_None},
-                                              {TTI::OK_UniformConstantValue, TTI::OP_None});
-      Cost += thisT()->getArithmeticInstrCost(Instruction::Shl, RetTy, CostKind,
-                                              {TTI::OK_AnyValue, TTI::OP_None},
-                                              {TTI::OK_UniformConstantValue, TTI::OP_None});
-      Cost += thisT()->getArithmeticInstrCost(Instruction::Or, RetTy, CostKind);
-      return Cost;
-    }
+      ISD = ISD::SMULFIX;
+      break;
+    case Intrinsic::umul_fix:
+      ISD = ISD::UMULFIX;
+      break;
     case Intrinsic::sadd_with_overflow:
       ISD = ISD::SADDO;
       break;
@@ -2413,6 +2394,30 @@ class BasicTTIImplBase : public TargetTransformInfoImplCRTPBase<T> {
                                       CmpInst::BAD_ICMP_PREDICATE, CostKind);
       return Cost;
     }
+    case Intrinsic::smul_fix:
+    case Intrinsic::umul_fix: {
+      unsigned ExtSize = RetTy->getScalarSizeInBits() * 2;
+      Type *ExtTy = RetTy->getWithNewBitWidth(ExtSize);
+
+      unsigned ExtOp =
+          IID == Intrinsic::smul_fix ? Instruction::SExt : Instruction::ZExt;
+      TTI::CastContextHint CCH = TTI::CastContextHint::None;
+
+      InstructionCost Cost = 0;
+      Cost += 2 * thisT()->getCastInstrCost(ExtOp, ExtTy, RetTy, CCH, CostKind);
+      Cost +=
+          thisT()->getArithmeticInstrCost(Instruction::Mul, ExtTy, CostKind);
+      Cost += 2 * thisT()->getCastInstrCost(Instruction::Trunc, RetTy, ExtTy,
+                                            CCH, CostKind);
+      Cost += thisT()->getArithmeticInstrCost(
+          Instruction::LShr, RetTy, CostKind, {TTI::OK_AnyValue, TTI::OP_None},
+          {TTI::OK_UniformConstantValue, TTI::OP_None});
+      Cost += thisT()->getArithmeticInstrCost(
+          Instruction::Shl, RetTy, CostKind, {TTI::OK_AnyValue, TTI::OP_None},
+          {TTI::OK_UniformConstantValue, TTI::OP_None});
+      Cost += thisT()->getArithmeticInstrCost(Instruction::Or, RetTy, CostKind);
+      return Cost;
+    }
     default:
       break;
     }

@arsenm arsenm force-pushed the users/arsenm/tti-mul-overflow-intrinsic-costs branch from c98dcbf to 5a2e8ac Compare July 25, 2024 17:28
@arsenm arsenm force-pushed the users/arsenm/tti-check-mulfix-legalize-costs branch from 689ea87 to 39ca2c4 Compare July 25, 2024 17:28
@arsenm arsenm force-pushed the users/arsenm/tti-mul-overflow-intrinsic-costs branch from 5a2e8ac to 3d683da Compare July 25, 2024 20:55
@arsenm arsenm force-pushed the users/arsenm/tti-check-mulfix-legalize-costs branch from 39ca2c4 to 1d17da3 Compare July 25, 2024 20:55
@arsenm arsenm force-pushed the users/arsenm/tti-mul-overflow-intrinsic-costs branch from 3d683da to f154bdb Compare July 26, 2024 20:00
@arsenm arsenm force-pushed the users/arsenm/tti-check-mulfix-legalize-costs branch from 1d17da3 to c382d2f Compare July 26, 2024 20:00
@arsenm arsenm force-pushed the users/arsenm/tti-mul-overflow-intrinsic-costs branch from f154bdb to 411c9c8 Compare July 28, 2024 13:48
@arsenm arsenm force-pushed the users/arsenm/tti-check-mulfix-legalize-costs branch from c382d2f to fc18583 Compare July 28, 2024 13:48
@arsenm arsenm force-pushed the users/arsenm/tti-mul-overflow-intrinsic-costs branch from 411c9c8 to 1b09d41 Compare August 2, 2024 16:25
@arsenm arsenm force-pushed the users/arsenm/tti-check-mulfix-legalize-costs branch from fc18583 to ac75fa0 Compare August 2, 2024 16:25
@arsenm arsenm force-pushed the users/arsenm/tti-mul-overflow-intrinsic-costs branch from 1b09d41 to f8959a5 Compare August 5, 2024 21:07
@arsenm arsenm force-pushed the users/arsenm/tti-check-mulfix-legalize-costs branch from ac75fa0 to 73397a6 Compare August 5, 2024 21:07
Copy link
Collaborator

@RKSimon RKSimon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - although I don't think we have any legal/custom cost test coverage (only x86 which exapands)

@arsenm arsenm force-pushed the users/arsenm/tti-mul-overflow-intrinsic-costs branch from f8959a5 to fd7e316 Compare August 6, 2024 18:27
@arsenm arsenm force-pushed the users/arsenm/tti-check-mulfix-legalize-costs branch from 73397a6 to 05c9703 Compare August 6, 2024 18:27
@arsenm arsenm force-pushed the users/arsenm/tti-mul-overflow-intrinsic-costs branch from fd7e316 to b6e75f2 Compare August 8, 2024 13:08
@arsenm arsenm force-pushed the users/arsenm/tti-check-mulfix-legalize-costs branch from 05c9703 to 2015249 Compare August 8, 2024 13:09
Copy link
Contributor Author

arsenm commented Aug 8, 2024

Merge activity

  • Aug 8, 3:40 PM EDT: @arsenm started a stack merge that includes this pull request via Graphite.
  • Aug 8, 3:51 PM EDT: Graphite rebased this pull request as part of a merge.
  • Aug 8, 3:54 PM EDT: @arsenm merged this pull request with Graphite.

@arsenm arsenm force-pushed the users/arsenm/tti-mul-overflow-intrinsic-costs branch 2 times, most recently from 294e59f to 92f7c1e Compare August 8, 2024 19:47
Base automatically changed from users/arsenm/tti-mul-overflow-intrinsic-costs to main August 8, 2024 19:50
@arsenm arsenm force-pushed the users/arsenm/tti-check-mulfix-legalize-costs branch from 2015249 to b58458d Compare August 8, 2024 19:50
@arsenm arsenm merged commit 6a48297 into main Aug 8, 2024
@arsenm arsenm deleted the users/arsenm/tti-check-mulfix-legalize-costs branch August 8, 2024 19:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend:AMDGPU llvm:analysis Includes value tracking, cost tables and constant folding llvm:transforms vectorizers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants