The expansion for wide subtractions includes G_USUBO, so it's important
that it's a legal instruction.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
Can you add selection tests for s32 and s64?
I think you can probably
- Copy test/CodeGen/AArch64/GlobalISel/select-uaddo.mir -> test/CodeGen/AArch64/GlobalISel/select-usubo.mir
- Replace G_UADDO with G_USUBO
- Generate the check lines using utils/update_mir_test_checks.py
and that should cover it.
llvm/test/CodeGen/AArch64/GlobalISel/legalize-add.mir | ||
---|---|---|
78 | I think I'd note in the commit message that you also improved testing for the other overflow ops. (Or, do this separately in a NFC commit.) Otherwise, someone 3 years down the line doing git history archaeology may be confused. :) |
Add the requested selection tests
I added usubo/saddo/ssubo tests here by duplicating the tests in select-uaddo.
Hi, looks like this patch broke UBSan on aarch64:
Looks like it flips the condition on unsigned-integer-overflow:
volatile uint32_t a = 1; volatile uint32_t b = 2; volatile uint32_t c = a - b;
17bc: 52800028 mov w8, #0x1 17c0: 71000908 subs w8, w8, #0x2 prev: 17c4: 54000142 b.cs 17ec no_problems // b.hs, b.nlast // fallthrough to __ubsan_handle_sub_overflow now: 17c4: 1a9f37e8 cset w8, cs // cs = hs, nlast 17c8: 360000c8 tbz w8, #0, no_problems // fallthrough to __ubsan_handle_sub_overflow
The reverse is also true, perfectly valid operands now fail:
int main() { volatile uint32_t a = 3; volatile uint32_t b = 2; volatile uint32_t c = a - b; }
$ clang a.cpp -fsanitize=unsigned-integer-overflow $ ./a.out runtime error: unsigned integer overflow: 3 - 2 cannot be represented in type 'unsigned int' SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior
This was caught on our sanitizer Android buildbots: http://lab.llvm.org:8011/#/builders/77/builds/3082
Fix instruction selection for G_USUBO
G_USUBO needs to be checked for overflow with the LO condition code instead of
the HS condition code. This should hopefully resolve the UBSan issue.
I think I'd note in the commit message that you also improved testing for the other overflow ops. (Or, do this separately in a NFC commit.) Otherwise, someone 3 years down the line doing git history archaeology may be confused. :)