Skip to content
This repository was archived by the owner on Mar 28, 2020. It is now read-only.

Commit 17c16d5

Browse files
committed
[InstCombine] improve perf by not creating a known non-canonical instruction
Op1 (RHS) is a constant, so putting it on the LHS makes us churn through visitICmp an extra time to canonicalize it: INSTCOMBINE ITERATION #1 on cmpnot IC: ADDING: 3 instrs to worklist IC: Visiting: %notx = xor i8 %x, -1 IC: Visiting: %cmp = icmp sgt i8 %notx, 42 IC: Old = %cmp = icmp sgt i8 %notx, 42 New = <badref> = icmp sgt i8 -43, %x IC: ADD: %cmp = icmp sgt i8 -43, %x IC: ERASE %1 = icmp sgt i8 %notx, 42 IC: ADD: %notx = xor i8 %x, -1 IC: DCE: %notx = xor i8 %x, -1 IC: ERASE %notx = xor i8 %x, -1 IC: Visiting: %cmp = icmp sgt i8 -43, %x IC: Mod = %cmp = icmp sgt i8 -43, %x New = %cmp = icmp slt i8 %x, -43 IC: ADD: %cmp = icmp slt i8 %x, -43 IC: Visiting: %cmp = icmp slt i8 %x, -43 IC: Visiting: ret i1 %cmp If we create the swapped ICmp directly, we go faster: INSTCOMBINE ITERATION #1 on cmpnot IC: ADDING: 3 instrs to worklist IC: Visiting: %notx = xor i8 %x, -1 IC: Visiting: %cmp = icmp sgt i8 %notx, 42 IC: Old = %cmp = icmp sgt i8 %notx, 42 New = <badref> = icmp slt i8 %x, -43 IC: ADD: %cmp = icmp slt i8 %x, -43 IC: ERASE %1 = icmp sgt i8 %notx, 42 IC: ADD: %notx = xor i8 %x, -1 IC: DCE: %notx = xor i8 %x, -1 IC: ERASE %notx = xor i8 %x, -1 IC: Visiting: %cmp = icmp slt i8 %x, -43 IC: Visiting: ret i1 %cmp git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@304558 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent ec35ada commit 17c16d5

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

lib/Transforms/InstCombine/InstCombineCompares.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4508,13 +4508,16 @@ Instruction *InstCombiner::visitICmpInst(ICmpInst &I) {
45084508
Builder->CreateAnd(A, B),
45094509
Op1);
45104510

4511-
// ~x < ~y --> y < x
4512-
// ~x < cst --> ~cst < x
4511+
// ~X < ~Y --> Y < X
4512+
// ~X < C --> X > ~C
45134513
if (match(Op0, m_Not(m_Value(A)))) {
45144514
if (match(Op1, m_Not(m_Value(B))))
45154515
return new ICmpInst(I.getPredicate(), B, A);
4516+
4517+
// FIXME: Use m_APInt to include splat vector constants.
45164518
if (ConstantInt *RHSC = dyn_cast<ConstantInt>(Op1))
4517-
return new ICmpInst(I.getPredicate(), ConstantExpr::getNot(RHSC), A);
4519+
return new ICmpInst(I.getSwappedPredicate(), A,
4520+
ConstantExpr::getNot(RHSC));
45184521
}
45194522

45204523
Instruction *AddI = nullptr;

0 commit comments

Comments
 (0)