Skip to content

Commit

Permalink
DAGCombine: Also shrink eq compares where the constant is exactly as …
Browse files Browse the repository at this point in the history
…large as the smaller type.

if ((x & 255) == 255)

before: movzbl  %al, %eax
        cmpl  $255, %eax

after:  cmpb  $-1, %al

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@182038 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
d0k committed May 16, 2013
1 parent afcca55 commit 8401ed2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/CodeGen/SelectionDAG/TargetLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1160,7 +1160,7 @@ TargetLowering::SimplifySetCC(EVT VT, SDValue N0, SDValue N1,
}

// Make sure we're not losing bits from the constant.
if (MinBits < C1.getBitWidth() && MinBits > C1.getActiveBits()) {
if (MinBits < C1.getBitWidth() && MinBits >= C1.getActiveBits()) {
EVT MinVT = EVT::getIntegerVT(*DAG.getContext(), MinBits);
if (isTypeDesirableForOp(ISD::SETCC, MinVT)) {
// Will get folded away.
Expand Down
16 changes: 16 additions & 0 deletions test/CodeGen/X86/shrink-compare.ll
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,19 @@ if.end:
; CHECK: test2:
; CHECK: cmpb $47, %{{dil|cl}}
}

define void @test3(i32 %X) nounwind {
entry:
%and = and i32 %X, 255
%cmp = icmp eq i32 %and, 255
br i1 %cmp, label %if.then, label %if.end

if.then:
tail call void @bar() nounwind
br label %if.end

if.end:
ret void
; CHECK: test3:
; CHECK: cmpb $-1, %{{dil|cl}}
}

0 comments on commit 8401ed2

Please sign in to comment.