mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-02-19 06:31:18 +00:00
Teach LowerBRCOND to recognize (xor (setcc x), 1). The xor inverts the condition. It's normally transformed by the dag combiner, unless the condition is set by a arithmetic op with overflow.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@63505 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
585c51efbc
commit
67ad9db15b
@ -5366,6 +5366,17 @@ static bool isAndOrOfSetCCs(SDValue Op, unsigned &Opc) {
|
|||||||
Op.getOperand(1).hasOneUse());
|
Op.getOperand(1).hasOneUse());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool isXor1OfSetCC(SDValue Op) {
|
||||||
|
if (Op.getOpcode() != ISD::XOR)
|
||||||
|
return false;
|
||||||
|
ConstantSDNode *N1C = dyn_cast<ConstantSDNode>(Op.getOperand(1));
|
||||||
|
if (N1C && N1C->getAPIntValue() == 1) {
|
||||||
|
return Op.getOperand(0).getOpcode() == X86ISD::SETCC &&
|
||||||
|
Op.getOperand(0).hasOneUse();
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
SDValue X86TargetLowering::LowerBRCOND(SDValue Op, SelectionDAG &DAG) {
|
SDValue X86TargetLowering::LowerBRCOND(SDValue Op, SelectionDAG &DAG) {
|
||||||
bool addTest = true;
|
bool addTest = true;
|
||||||
SDValue Chain = Op.getOperand(0);
|
SDValue Chain = Op.getOperand(0);
|
||||||
@ -5460,6 +5471,16 @@ SDValue X86TargetLowering::LowerBRCOND(SDValue Op, SelectionDAG &DAG) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else if (Cond.hasOneUse() && isXor1OfSetCC(Cond)) {
|
||||||
|
// Recognize for xorb (setcc), 1 patterns. The xor inverts the condition.
|
||||||
|
// It should be transformed during dag combiner except when the condition
|
||||||
|
// is set by a arithmetics with overflow node.
|
||||||
|
X86::CondCode CCode =
|
||||||
|
(X86::CondCode)Cond.getOperand(0).getConstantOperandVal(0);
|
||||||
|
CCode = X86::GetOppositeBranchCondition(CCode);
|
||||||
|
CC = DAG.getConstant(CCode, MVT::i8);
|
||||||
|
Cond = Cond.getOperand(0).getOperand(1);
|
||||||
|
addTest = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
23
test/CodeGen/X86/smul-with-overflow-3.ll
Normal file
23
test/CodeGen/X86/smul-with-overflow-3.ll
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
; RUN: llvm-as < %s | llc -march=x86 | grep {jno} | count 1
|
||||||
|
|
||||||
|
@ok = internal constant [4 x i8] c"%d\0A\00"
|
||||||
|
@no = internal constant [4 x i8] c"no\0A\00"
|
||||||
|
|
||||||
|
define i1 @func1(i32 %v1, i32 %v2) nounwind {
|
||||||
|
entry:
|
||||||
|
%t = call {i32, i1} @llvm.smul.with.overflow.i32(i32 %v1, i32 %v2)
|
||||||
|
%sum = extractvalue {i32, i1} %t, 0
|
||||||
|
%obit = extractvalue {i32, i1} %t, 1
|
||||||
|
br i1 %obit, label %overflow, label %normal
|
||||||
|
|
||||||
|
overflow:
|
||||||
|
%t2 = tail call i32 (i8*, ...)* @printf( i8* getelementptr ([4 x i8]* @no, i32 0, i32 0) ) nounwind
|
||||||
|
ret i1 false
|
||||||
|
|
||||||
|
normal:
|
||||||
|
%t1 = tail call i32 (i8*, ...)* @printf( i8* getelementptr ([4 x i8]* @ok, i32 0, i32 0), i32 %sum ) nounwind
|
||||||
|
ret i1 true
|
||||||
|
}
|
||||||
|
|
||||||
|
declare i32 @printf(i8*, ...) nounwind
|
||||||
|
declare {i32, i1} @llvm.smul.with.overflow.i32(i32, i32)
|
Loading…
x
Reference in New Issue
Block a user