Skip to content

Commit

Permalink
Switch lowering: fix assert in buildBitTests (PR23738)
Browse files Browse the repository at this point in the history
When checking (High - Low + 1).sle(BitWidth), BitWidth would be truncated
to the size of the left-hand side. In the case of this PR, the left-hand
side was i4, so BitWidth=64 got truncated to 0 and the assert failed.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@239048 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
zmodem committed Jun 4, 2015
1 parent 9f299ab commit bebb0b5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7614,7 +7614,8 @@ bool SelectionDAGBuilder::buildBitTests(CaseClusterVector &Clusters,

const int BitWidth =
DAG.getTargetLoweringInfo().getPointerTy().getSizeInBits();
assert((High - Low + 1).sle(BitWidth) && "Case range must fit in bit mask!");
uint64_t Range = (High - Low).getLimitedValue(UINT64_MAX - 1) + 1;
assert(Range <= (uint64_t)BitWidth && "Case range must fit in bit mask!");

if (Low.isNonNegative() && High.slt(BitWidth)) {
// Optimize the case where all the case values fit in a
Expand Down
15 changes: 15 additions & 0 deletions test/CodeGen/X86/switch.ll
Original file line number Diff line number Diff line change
Expand Up @@ -534,3 +534,18 @@ return: ret void
; CHECK-NOT: cmpl
; CHECK: cmpl $99
}


define void @pr23738(i4 %x) {
entry:
switch i4 %x, label %bb0 [
i4 0, label %bb1
i4 1, label %bb1
i4 -5, label %bb1
]
bb0: tail call void @g(i32 0) br label %return
bb1: tail call void @g(i32 1) br label %return
return: ret void
; Don't assert due to truncating the bitwidth (64) to i4 when checking
; that the bit-test range fits in a word.
}

0 comments on commit bebb0b5

Please sign in to comment.