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
Paths
| Differential D140747
[Transform] Rewrite LowerSwitch using APInt ClosedPublic Authored by Peter on Dec 28 2022, 5:49 PM.
Details Summary 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
Event TimelinePeter retitled this revision from [Transform] Rewrite LowerSwitch using APInt
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... to [Transform] Rewrite LowerSwitch using APInt.Dec 28 2022, 5:52 PM arsenm added inline comments. Peter marked 2 inline comments as done. Comment Actions
Comment 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. This revision now requires changes to proceed.Jan 2 2023, 1:33 PM
This revision is now accepted and ready to land.Jan 5 2023, 9:42 AM Closed by commit rG1db51d8eb2d2: [Transform] Rewrite LowerSwitch using APInt (authored by Peter). · Explain WhyJan 5 2023, 2:30 PM This revision was automatically updated to reflect the committed changes. 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. bbi-77637.ll261 BDownload
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.) This revision is now accepted and ready to land.Jan 12 2023, 10:41 AM 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 revision is now accepted and ready to land.Jan 24 2023, 5:23 AM Closed by commit rG9b70a28e0d76: [Transform] Rewrite LowerSwitch using APInt (authored by Peter). · Explain WhyJan 24 2023, 8:22 PM This revision was automatically updated to reflect the committed changes.
Revision Contents
Diff 491991 llvm/lib/Transforms/Utils/LowerSwitch.cpp
llvm/test/Transforms/LowerSwitch/pr59316.ll
|
This was >= before