This rewrite fixes https://github.com/llvm/llvm-project/issues/59316.
Previously LowerSwitch uses int64_t, which will crash on case branches using integers with more than 64 bits.
Using APInt fixes this problem. This patch also includes a test
Differential D140747
[Transform] Rewrite LowerSwitch using APInt Peter on Dec 28 2022, 5:49 PM. Authored by
Details This rewrite fixes https://github.com/llvm/llvm-project/issues/59316. Previously LowerSwitch uses int64_t, which will crash on case branches using integers with more than 64 bits.
Diff Detail
Unit Tests Event TimelineComment Actions The old code assumes the branch case to be signed integer (int64_t), therefore some place use APSInt to make signess more clear. Comment Actions APSInt is only used if you need to dynamically switch between signed and unsigned operations. Otherwise APInt with appropriate operations is used -- there are signed and unsigned variants for all operations where it makes a difference.
Comment Actions Hello, The following starts crashing with this patch: opt -passes=lowerswitch bbi-77637.ll -o /dev/null It fails with opt: ../lib/Transforms/Utils/LowerSwitch.cpp:461: void (anonymous namespace)::ProcessSwitchInst(llvm::SwitchInst *, SmallPtrSetImpl<llvm::BasicBlock *> &, llvm::AssumptionCache *, llvm::LazyValueInfo *): Assertion `N.sge(SignedZero) && "Popularity shouldn't be negative."' failed.
Comment Actions Not just i1 but for any type. (Easiest to trigger on i1 tho). The root cause is N = High - Low + 1 may overflow to a negative number. (Imagine i32 N = i32::max - i32::min + 1 as signed.) Comment Actions Popularity is now represented using higher precision unsigned APInt to avoid overflow
Comment Actions We see the Assertion `N.sge(SignedZero) && "Popularity shouldn't be negative."' failed. crash fairly often in downstream fuzz testing. Comment Actions I think this problems have already been fixed in this patch. I am waiting for someone to review it before I patch it.
|
This was >= before