[llvm] [WebAssembly] Don't fold non-nuw add/sub in FastISel (PR #111278)

Heejin Ahn via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 8 10:59:40 PDT 2024


================
@@ -337,6 +337,12 @@ bool WebAssemblyFastISel::computeAddress(const Value *Obj, Address &Addr) {
     break;
   }
   case Instruction::Add: {
+    // We should not fold operands into an offset when 'nuw' (no unsigned wrap)
+    // is not present, because the address calculation does not wrap.
+    if (auto *OFBinOp = dyn_cast<OverflowingBinaryOperator>(U))
+      if (!OFBinOp->hasNoUnsignedWrap())
----------------
aheejin wrote:

You are right! I was misunderstanding the "one reg" rule in FastISel. If FastISel cannot figure out how to make use of the offset, it assigns the whole expression to a single register, which then generates more instructions to make it happen (by adding more registers for its child expressions):
https://github.com/llvm/llvm-project/blob/c563fe5c71239a8938e1925fce4c19954564faf0/llvm/lib/Target/WebAssembly/WebAssemblyFastISel.cpp#L380

Anyway, changed them to `break`s, and renamed the test file and added `-fast-isel-abort=1` because we don't bail out of FastISel anymore. Thanks!

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


More information about the llvm-commits mailing list