ncw created this revision.
ncw added reviewers: sunfish, dschuff.
Herald added subscribers: cfe-commits, aheejin, jgravelle-google, sbc100, jfb.

See: https://bugs.llvm.org/show_bug.cgi?id=35582

Since Wasm has to use 32-to-16 bit instructions to narrow values down, 32-bit 
should be a tad faster for operations needing 16 or more bits.


Repository:
  rC Clang

https://reviews.llvm.org/D41941

Files:
  lib/Basic/Targets/WebAssembly.h
  test/Preprocessor/init.c

Index: test/Preprocessor/init.c
===================================================================
--- test/Preprocessor/init.c
+++ test/Preprocessor/init.c
@@ -9166,10 +9166,10 @@
 // WEBASSEMBLY32-NEXT:#define __INTPTR_MAX__ 2147483647
 // WEBASSEMBLY32-NEXT:#define __INTPTR_TYPE__ int
 // WEBASSEMBLY32-NEXT:#define __INTPTR_WIDTH__ 32
-// WEBASSEMBLY32-NEXT:#define __INT_FAST16_FMTd__ "hd"
-// WEBASSEMBLY32-NEXT:#define __INT_FAST16_FMTi__ "hi"
-// WEBASSEMBLY32-NEXT:#define __INT_FAST16_MAX__ 32767
-// WEBASSEMBLY32-NEXT:#define __INT_FAST16_TYPE__ short
+// WEBASSEMBLY32-NEXT:#define __INT_FAST16_FMTd__ "d"
+// WEBASSEMBLY32-NEXT:#define __INT_FAST16_FMTi__ "i"
+// WEBASSEMBLY32-NEXT:#define __INT_FAST16_MAX__ 2147483647
+// WEBASSEMBLY32-NEXT:#define __INT_FAST16_TYPE__ int
 // WEBASSEMBLY32-NEXT:#define __INT_FAST32_FMTd__ "d"
 // WEBASSEMBLY32-NEXT:#define __INT_FAST32_FMTi__ "i"
 // WEBASSEMBLY32-NEXT:#define __INT_FAST32_MAX__ 2147483647
@@ -9182,10 +9182,10 @@
 // WEBASSEMBLY32-NEXT:#define __INT_FAST8_FMTi__ "hhi"
 // WEBASSEMBLY32-NEXT:#define __INT_FAST8_MAX__ 127
 // WEBASSEMBLY32-NEXT:#define __INT_FAST8_TYPE__ signed char
-// WEBASSEMBLY32-NEXT:#define __INT_LEAST16_FMTd__ "hd"
-// WEBASSEMBLY32-NEXT:#define __INT_LEAST16_FMTi__ "hi"
-// WEBASSEMBLY32-NEXT:#define __INT_LEAST16_MAX__ 32767
-// WEBASSEMBLY32-NEXT:#define __INT_LEAST16_TYPE__ short
+// WEBASSEMBLY32-NEXT:#define __INT_LEAST16_FMTd__ "d"
+// WEBASSEMBLY32-NEXT:#define __INT_LEAST16_FMTi__ "i"
+// WEBASSEMBLY32-NEXT:#define __INT_LEAST16_MAX__ 2147483647
+// WEBASSEMBLY32-NEXT:#define __INT_LEAST16_TYPE__ int
 // WEBASSEMBLY32-NEXT:#define __INT_LEAST32_FMTd__ "d"
 // WEBASSEMBLY32-NEXT:#define __INT_LEAST32_FMTi__ "i"
 // WEBASSEMBLY32-NEXT:#define __INT_LEAST32_MAX__ 2147483647
@@ -9312,12 +9312,12 @@
 // WEBASSEMBLY32-NEXT:#define __UINTPTR_MAX__ 4294967295U
 // WEBASSEMBLY32-NEXT:#define __UINTPTR_TYPE__ unsigned int
 // WEBASSEMBLY32-NEXT:#define __UINTPTR_WIDTH__ 32
-// WEBASSEMBLY32-NEXT:#define __UINT_FAST16_FMTX__ "hX"
-// WEBASSEMBLY32-NEXT:#define __UINT_FAST16_FMTo__ "ho"
-// WEBASSEMBLY32-NEXT:#define __UINT_FAST16_FMTu__ "hu"
-// WEBASSEMBLY32-NEXT:#define __UINT_FAST16_FMTx__ "hx"
-// WEBASSEMBLY32-NEXT:#define __UINT_FAST16_MAX__ 65535
-// WEBASSEMBLY32-NEXT:#define __UINT_FAST16_TYPE__ unsigned short
+// WEBASSEMBLY32-NEXT:#define __UINT_FAST16_FMTX__ "X"
+// WEBASSEMBLY32-NEXT:#define __UINT_FAST16_FMTo__ "o"
+// WEBASSEMBLY32-NEXT:#define __UINT_FAST16_FMTu__ "u"
+// WEBASSEMBLY32-NEXT:#define __UINT_FAST16_FMTx__ "x"
+// WEBASSEMBLY32-NEXT:#define __UINT_FAST16_MAX__ 4294967295U
+// WEBASSEMBLY32-NEXT:#define __UINT_FAST16_TYPE__ unsigned int
 // WEBASSEMBLY32-NEXT:#define __UINT_FAST32_FMTX__ "X"
 // WEBASSEMBLY32-NEXT:#define __UINT_FAST32_FMTo__ "o"
 // WEBASSEMBLY32-NEXT:#define __UINT_FAST32_FMTu__ "u"
@@ -9336,12 +9336,12 @@
 // WEBASSEMBLY32-NEXT:#define __UINT_FAST8_FMTx__ "hhx"
 // WEBASSEMBLY32-NEXT:#define __UINT_FAST8_MAX__ 255
 // WEBASSEMBLY32-NEXT:#define __UINT_FAST8_TYPE__ unsigned char
-// WEBASSEMBLY32-NEXT:#define __UINT_LEAST16_FMTX__ "hX"
-// WEBASSEMBLY32-NEXT:#define __UINT_LEAST16_FMTo__ "ho"
-// WEBASSEMBLY32-NEXT:#define __UINT_LEAST16_FMTu__ "hu"
-// WEBASSEMBLY32-NEXT:#define __UINT_LEAST16_FMTx__ "hx"
-// WEBASSEMBLY32-NEXT:#define __UINT_LEAST16_MAX__ 65535
-// WEBASSEMBLY32-NEXT:#define __UINT_LEAST16_TYPE__ unsigned short
+// WEBASSEMBLY32-NEXT:#define __UINT_LEAST16_FMTX__ "X"
+// WEBASSEMBLY32-NEXT:#define __UINT_LEAST16_FMTo__ "o"
+// WEBASSEMBLY32-NEXT:#define __UINT_LEAST16_FMTu__ "u"
+// WEBASSEMBLY32-NEXT:#define __UINT_LEAST16_FMTx__ "x"
+// WEBASSEMBLY32-NEXT:#define __UINT_LEAST16_MAX__ 4294967295U
+// WEBASSEMBLY32-NEXT:#define __UINT_LEAST16_TYPE__ unsigned int
 // WEBASSEMBLY32-NEXT:#define __UINT_LEAST32_FMTX__ "X"
 // WEBASSEMBLY32-NEXT:#define __UINT_LEAST32_FMTo__ "o"
 // WEBASSEMBLY32-NEXT:#define __UINT_LEAST32_FMTu__ "u"
@@ -9498,10 +9498,10 @@
 // WEBASSEMBLY64-NEXT:#define __INTPTR_MAX__ 9223372036854775807L
 // WEBASSEMBLY64-NEXT:#define __INTPTR_TYPE__ long int
 // WEBASSEMBLY64-NEXT:#define __INTPTR_WIDTH__ 64
-// WEBASSEMBLY64-NEXT:#define __INT_FAST16_FMTd__ "hd"
-// WEBASSEMBLY64-NEXT:#define __INT_FAST16_FMTi__ "hi"
-// WEBASSEMBLY64-NEXT:#define __INT_FAST16_MAX__ 32767
-// WEBASSEMBLY64-NEXT:#define __INT_FAST16_TYPE__ short
+// WEBASSEMBLY64-NEXT:#define __INT_FAST16_FMTd__ "d"
+// WEBASSEMBLY64-NEXT:#define __INT_FAST16_FMTi__ "i"
+// WEBASSEMBLY64-NEXT:#define __INT_FAST16_MAX__ 2147483647
+// WEBASSEMBLY64-NEXT:#define __INT_FAST16_TYPE__ int
 // WEBASSEMBLY64-NEXT:#define __INT_FAST32_FMTd__ "d"
 // WEBASSEMBLY64-NEXT:#define __INT_FAST32_FMTi__ "i"
 // WEBASSEMBLY64-NEXT:#define __INT_FAST32_MAX__ 2147483647
@@ -9514,10 +9514,10 @@
 // WEBASSEMBLY64-NEXT:#define __INT_FAST8_FMTi__ "hhi"
 // WEBASSEMBLY64-NEXT:#define __INT_FAST8_MAX__ 127
 // WEBASSEMBLY64-NEXT:#define __INT_FAST8_TYPE__ signed char
-// WEBASSEMBLY64-NEXT:#define __INT_LEAST16_FMTd__ "hd"
-// WEBASSEMBLY64-NEXT:#define __INT_LEAST16_FMTi__ "hi"
-// WEBASSEMBLY64-NEXT:#define __INT_LEAST16_MAX__ 32767
-// WEBASSEMBLY64-NEXT:#define __INT_LEAST16_TYPE__ short
+// WEBASSEMBLY64-NEXT:#define __INT_LEAST16_FMTd__ "d"
+// WEBASSEMBLY64-NEXT:#define __INT_LEAST16_FMTi__ "i"
+// WEBASSEMBLY64-NEXT:#define __INT_LEAST16_MAX__ 2147483647
+// WEBASSEMBLY64-NEXT:#define __INT_LEAST16_TYPE__ int
 // WEBASSEMBLY64-NEXT:#define __INT_LEAST32_FMTd__ "d"
 // WEBASSEMBLY64-NEXT:#define __INT_LEAST32_FMTi__ "i"
 // WEBASSEMBLY64-NEXT:#define __INT_LEAST32_MAX__ 2147483647
@@ -9644,12 +9644,12 @@
 // WEBASSEMBLY64-NEXT:#define __UINTPTR_MAX__ 18446744073709551615UL
 // WEBASSEMBLY64-NEXT:#define __UINTPTR_TYPE__ long unsigned int
 // WEBASSEMBLY64-NEXT:#define __UINTPTR_WIDTH__ 64
-// WEBASSEMBLY64-NEXT:#define __UINT_FAST16_FMTX__ "hX"
-// WEBASSEMBLY64-NEXT:#define __UINT_FAST16_FMTo__ "ho"
-// WEBASSEMBLY64-NEXT:#define __UINT_FAST16_FMTu__ "hu"
-// WEBASSEMBLY64-NEXT:#define __UINT_FAST16_FMTx__ "hx"
-// WEBASSEMBLY64-NEXT:#define __UINT_FAST16_MAX__ 65535
-// WEBASSEMBLY64-NEXT:#define __UINT_FAST16_TYPE__ unsigned short
+// WEBASSEMBLY64-NEXT:#define __UINT_FAST16_FMTX__ "X"
+// WEBASSEMBLY64-NEXT:#define __UINT_FAST16_FMTo__ "o"
+// WEBASSEMBLY64-NEXT:#define __UINT_FAST16_FMTu__ "u"
+// WEBASSEMBLY64-NEXT:#define __UINT_FAST16_FMTx__ "x"
+// WEBASSEMBLY64-NEXT:#define __UINT_FAST16_MAX__ 4294967295U
+// WEBASSEMBLY64-NEXT:#define __UINT_FAST16_TYPE__ unsigned int
 // WEBASSEMBLY64-NEXT:#define __UINT_FAST32_FMTX__ "X"
 // WEBASSEMBLY64-NEXT:#define __UINT_FAST32_FMTo__ "o"
 // WEBASSEMBLY64-NEXT:#define __UINT_FAST32_FMTu__ "u"
@@ -9668,12 +9668,12 @@
 // WEBASSEMBLY64-NEXT:#define __UINT_FAST8_FMTx__ "hhx"
 // WEBASSEMBLY64-NEXT:#define __UINT_FAST8_MAX__ 255
 // WEBASSEMBLY64-NEXT:#define __UINT_FAST8_TYPE__ unsigned char
-// WEBASSEMBLY64-NEXT:#define __UINT_LEAST16_FMTX__ "hX"
-// WEBASSEMBLY64-NEXT:#define __UINT_LEAST16_FMTo__ "ho"
-// WEBASSEMBLY64-NEXT:#define __UINT_LEAST16_FMTu__ "hu"
-// WEBASSEMBLY64-NEXT:#define __UINT_LEAST16_FMTx__ "hx"
-// WEBASSEMBLY64-NEXT:#define __UINT_LEAST16_MAX__ 65535
-// WEBASSEMBLY64-NEXT:#define __UINT_LEAST16_TYPE__ unsigned short
+// WEBASSEMBLY64-NEXT:#define __UINT_LEAST16_FMTX__ "X"
+// WEBASSEMBLY64-NEXT:#define __UINT_LEAST16_FMTo__ "o"
+// WEBASSEMBLY64-NEXT:#define __UINT_LEAST16_FMTu__ "u"
+// WEBASSEMBLY64-NEXT:#define __UINT_LEAST16_FMTx__ "x"
+// WEBASSEMBLY64-NEXT:#define __UINT_LEAST16_MAX__ 4294967295U
+// WEBASSEMBLY64-NEXT:#define __UINT_LEAST16_TYPE__ unsigned int
 // WEBASSEMBLY64-NEXT:#define __UINT_LEAST32_FMTX__ "X"
 // WEBASSEMBLY64-NEXT:#define __UINT_LEAST32_FMTo__ "o"
 // WEBASSEMBLY64-NEXT:#define __UINT_LEAST32_FMTu__ "u"
Index: lib/Basic/Targets/WebAssembly.h
===================================================================
--- lib/Basic/Targets/WebAssembly.h
+++ lib/Basic/Targets/WebAssembly.h
@@ -97,14 +97,19 @@
   bool hasInt128Type() const final { return true; }
 
   IntType getIntTypeByWidth(unsigned BitWidth, bool IsSigned) const final {
-    // WebAssembly prefers long long for explicitly 64-bit integers.
-    return BitWidth == 64 ? (IsSigned ? SignedLongLong : UnsignedLongLong)
+    // WebAssembly prefers long long for explicitly 64-bit integers, and int for
+    // 16-bit integers.
+    return BitWidth == 16 ? (IsSigned ? SignedInt : UnsignedInt) :
+           BitWidth == 64 ? (IsSigned ? SignedLongLong : UnsignedLongLong)
                           : TargetInfo::getIntTypeByWidth(BitWidth, IsSigned);
   }
 
   IntType getLeastIntTypeByWidth(unsigned BitWidth, bool IsSigned) const final {
-    // WebAssembly uses long long for int_least64_t and int_fast64_t.
-    return BitWidth == 64
+    // WebAssembly uses long long for int_least64_t and int_fast64_t, and int
+    // for int_least16_t and int_fast16_t.
+    return BitWidth == 16
+               ? (IsSigned ? SignedInt : UnsignedInt) :
+           BitWidth == 64
                ? (IsSigned ? SignedLongLong : UnsignedLongLong)
                : TargetInfo::getLeastIntTypeByWidth(BitWidth, IsSigned);
   }
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to