[llvm] [WebAssembly] Select BUILD_VECTOR with large unsigned lane values (PR #85880)

Heejin Ahn via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 19 18:24:14 PDT 2024


================
@@ -46,10 +46,12 @@ defm "" : ARGUMENT<V128, v2i64>;
 defm "" : ARGUMENT<V128, v4f32>;
 defm "" : ARGUMENT<V128, v2f64>;
 
-// Constrained immediate argument types
+// Constrained immediate argument types. Allow any value from the minimum signed
+// value to the maximum unsigned value for the lane size.
 foreach SIZE = [8, 16] in
 def ImmI#SIZE : ImmLeaf<i32,
-  "return -(1 << ("#SIZE#" - 1)) <= Imm && Imm < (1 << ("#SIZE#" - 1));"
+  // -2^(n-1) <= Imm <= 2^n-1, avoiding UB when n == 64.
+  "return -(1 << ("#SIZE#" - 1)) <= Imm && Imm <= int64_t(uint64_t(1 << ("#SIZE#" - 1) << 1) - 1);"
----------------
aheejin wrote:

- Why do we need `1 << ("#SIZE#" - 1) << 1`? Can't we just use `1 << "#SIZE#"`?
- Can you elaborate what `uint64_t` and `int64_t` casting do and what is the UB about?
- Why do we need to consider `n  == 64`, give that this is under `foreach SIZE = [8, 16]`?

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


More information about the llvm-commits mailing list