[llvm] [ADT] Add implementations for mulhs and mulhu to APInt (PR #84609)
    Jay Foad via llvm-commits 
    llvm-commits at lists.llvm.org
       
    Sat Mar  9 01:06:44 PST 2024
    
    
  
================
@@ -6015,17 +6015,11 @@ static std::optional<APInt> FoldValue(unsigned Opcode, const APInt &C1,
     if (!C2.getBoolValue())
       break;
     return C1.srem(C2);
-  case ISD::MULHS: {
-    unsigned FullWidth = C1.getBitWidth() * 2;
-    APInt C1Ext = C1.sext(FullWidth);
-    APInt C2Ext = C2.sext(FullWidth);
-    return (C1Ext * C2Ext).extractBits(C1.getBitWidth(), C1.getBitWidth());
-  }
   case ISD::MULHU: {
-    unsigned FullWidth = C1.getBitWidth() * 2;
-    APInt C1Ext = C1.zext(FullWidth);
-    APInt C2Ext = C2.zext(FullWidth);
-    return (C1Ext * C2Ext).extractBits(C1.getBitWidth(), C1.getBitWidth());
+    return APIntOps::mulhu(C1, C2);
+  }
+  case ISD::MULHS: {
+    return APIntOps::mulhs(C1, C2);
----------------
jayfoad wrote:
Nit: don't need braces.
https://github.com/llvm/llvm-project/pull/84609
    
    
More information about the llvm-commits
mailing list