This is an archive of the discontinued LLVM Phabricator instance.

[WebAssembly] Don't fold frame offset for global addresses
ClosedPublic

Authored by aheejin on Nov 1 2020, 5:35 PM.

Details

Summary

When machine instructions are in the form of

%0 = CONST_I32 @str
%1 = ADD_I32 %stack.0, %0
%2 = LOAD 0, 0, %1

In the ADD_I32 instruction, it is possible to fold it if %0 is a
CONST_I32 from an immediate number. But in this case it is a global
address, so we shouldn't do that. But we haven't checked if the operand
of ADD is an immediate so far. This fixes the problem. (The case
applies the same for ADD_I64 and CONST_I64 instructions.)

Fixes https://bugs.llvm.org/show_bug.cgi?id=47944.

Patch by Julien Jorge (jjorge@quarkslab.com)

Diff Detail

Event Timeline

aheejin created this revision.Nov 1 2020, 5:35 PM
Herald added a project: Restricted Project. · View Herald TranscriptNov 1 2020, 5:35 PM
aheejin requested review of this revision.Nov 1 2020, 5:35 PM
aheejin edited the summary of this revision. (Show Details)Nov 1 2020, 5:36 PM
aheejin edited the summary of this revision. (Show Details)
aheejin edited the summary of this revision. (Show Details)Nov 1 2020, 5:43 PM
aheejin updated this revision to Diff 302383.Nov 2 2020, 1:15 PM
  • Fix comment wrapping

I think in theory, we could actually keep this optimization if we had a (ULEB?) relocation type with an addend (I think R_WASM_MEMORY_ADDR_LEB would work, actually).
Then we'd emit a load with a reloc against its constant offset field, where the addend would be the frame offset and the symbol would be the operand (similarly to what LadPatImmOff does for ISel)?
Of course if nobody discovered this bug before now it might not be that worthwhile...

I guess that optimization cannot be done here and should be done later? And there's also an existing TODO to generalize this optimization. Maybe we can do it as a part of the 'generalization' later? But I also doubt how worthwhile it will be, given that this bug was found first time 5 years after this part of the code was first written...

dschuff accepted this revision.Nov 3 2020, 2:26 PM

oh, I guess you're referring to the TODO on line 97? Yeah I guess including the case where the operand is a GA instead of an immediate counts as "more cases"...

This revision is now accepted and ready to land.Nov 3 2020, 2:26 PM
This revision was landed with ongoing or failed builds.Nov 3 2020, 2:57 PM
This revision was automatically updated to reflect the committed changes.