[llvm] r187571 - [SystemZ] Prefer comparisons with zero
Richard Sandiford
rsandifo at linux.vnet.ibm.com
Thu Aug 1 03:29:46 PDT 2013
Author: rsandifo
Date: Thu Aug 1 05:29:45 2013
New Revision: 187571
URL: http://llvm.org/viewvc/llvm-project?rev=187571&view=rev
Log:
[SystemZ] Prefer comparisons with zero
Convert >= 1 to > 0, etc. Using comparison with zero isn't a win on its own,
but it exposes more opportunities for CC reuse (the next patch).
Modified:
llvm/trunk/lib/Target/SystemZ/SystemZISelLowering.cpp
llvm/trunk/test/CodeGen/SystemZ/int-cmp-09.ll
llvm/trunk/test/CodeGen/SystemZ/int-cmp-11.ll
llvm/trunk/test/CodeGen/SystemZ/int-cmp-22.ll
llvm/trunk/test/CodeGen/SystemZ/int-cmp-32.ll
llvm/trunk/test/CodeGen/SystemZ/int-cmp-34.ll
Modified: llvm/trunk/lib/Target/SystemZ/SystemZISelLowering.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/SystemZ/SystemZISelLowering.cpp?rev=187571&r1=187570&r2=187571&view=diff
==============================================================================
--- llvm/trunk/lib/Target/SystemZ/SystemZISelLowering.cpp (original)
+++ llvm/trunk/lib/Target/SystemZ/SystemZISelLowering.cpp Thu Aug 1 05:29:45 2013
@@ -911,6 +911,29 @@ static unsigned CCMaskForCondCode(ISD::C
}
// If a comparison described by IsUnsigned, CCMask, CmpOp0 and CmpOp1
+// can be converted to a comparison against zero, adjust the operands
+// as necessary.
+static void adjustZeroCmp(SelectionDAG &DAG, bool &IsUnsigned,
+ SDValue &CmpOp0, SDValue &CmpOp1,
+ unsigned &CCMask) {
+ if (IsUnsigned)
+ return;
+
+ ConstantSDNode *ConstOp1 = dyn_cast<ConstantSDNode>(CmpOp1.getNode());
+ if (!ConstOp1)
+ return;
+
+ int64_t Value = ConstOp1->getSExtValue();
+ if ((Value == -1 && CCMask == SystemZ::CCMASK_CMP_GT) ||
+ (Value == -1 && CCMask == SystemZ::CCMASK_CMP_LE) ||
+ (Value == 1 && CCMask == SystemZ::CCMASK_CMP_LT) ||
+ (Value == 1 && CCMask == SystemZ::CCMASK_CMP_GE)) {
+ CCMask ^= SystemZ::CCMASK_CMP_EQ;
+ CmpOp1 = DAG.getConstant(0, CmpOp1.getValueType());
+ }
+}
+
+// If a comparison described by IsUnsigned, CCMask, CmpOp0 and CmpOp1
// is suitable for CLI(Y), CHHSI or CLHHSI, adjust the operands as necessary.
static void adjustSubwordCmp(SelectionDAG &DAG, bool &IsUnsigned,
SDValue &CmpOp0, SDValue &CmpOp1,
@@ -954,7 +977,7 @@ static void adjustSubwordCmp(SelectionDA
if (Value == 0 && CCMask == SystemZ::CCMASK_CMP_LT)
// Test whether the high bit of the byte is set.
Value = 127, CCMask = SystemZ::CCMASK_CMP_GT, IsUnsigned = true;
- else if (SignedValue == -1 && CCMask == SystemZ::CCMASK_CMP_GT)
+ else if (Value == 0 && CCMask == SystemZ::CCMASK_CMP_GE)
// Test whether the high bit of the byte is clear.
Value = 128, CCMask = SystemZ::CCMASK_CMP_LT, IsUnsigned = true;
else
@@ -1045,6 +1068,7 @@ static SDValue emitCmp(SelectionDAG &DAG
IsUnsigned = CCMask & SystemZ::CCMASK_CMP_UO;
CCValid = SystemZ::CCMASK_ICMP;
CCMask &= CCValid;
+ adjustZeroCmp(DAG, IsUnsigned, CmpOp0, CmpOp1, CCMask);
adjustSubwordCmp(DAG, IsUnsigned, CmpOp0, CmpOp1, CCMask);
if (preferUnsignedComparison(DAG, CmpOp0, CmpOp1, CCMask))
IsUnsigned = true;
Modified: llvm/trunk/test/CodeGen/SystemZ/int-cmp-09.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/SystemZ/int-cmp-09.ll?rev=187571&r1=187570&r2=187571&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/SystemZ/int-cmp-09.ll (original)
+++ llvm/trunk/test/CodeGen/SystemZ/int-cmp-09.ll Thu Aug 1 05:29:45 2013
@@ -13,13 +13,13 @@ define double @f1(double %a, double %b,
ret double %res
}
-; Check comparisons with 1.
+; Check comparisons with 2.
define double @f2(double %a, double %b, i32 %i1) {
; CHECK-LABEL: f2:
-; CHECK: cijl %r2, 1
+; CHECK: cijl %r2, 2
; CHECK: ldr %f0, %f2
; CHECK: br %r14
- %cond = icmp slt i32 %i1, 1
+ %cond = icmp slt i32 %i1, 2
%res = select i1 %cond, double %a, double %b
ret double %res
}
@@ -176,3 +176,47 @@ define double @f15(double %a, double %b,
%res = select i1 %cond, double %a, double %b
ret double %res
}
+
+; Check that < 1 becomes <= 0.
+define double @f16(double %a, double %b, i32 %i1) {
+; CHECK-LABEL: f16:
+; CHECK: cijle %r2, 0
+; CHECK: ldr %f0, %f2
+; CHECK: br %r14
+ %cond = icmp slt i32 %i1, 1
+ %res = select i1 %cond, double %a, double %b
+ ret double %res
+}
+
+; Check that >= 1 becomes > 0.
+define double @f17(double %a, double %b, i32 %i1) {
+; CHECK-LABEL: f17:
+; CHECK: cijh %r2, 0
+; CHECK: ldr %f0, %f2
+; CHECK: br %r14
+ %cond = icmp sge i32 %i1, 1
+ %res = select i1 %cond, double %a, double %b
+ ret double %res
+}
+
+; Check that > -1 becomes >= 0.
+define double @f18(double %a, double %b, i32 %i1) {
+; CHECK-LABEL: f18:
+; CHECK: cijhe %r2, 0
+; CHECK: ldr %f0, %f2
+; CHECK: br %r14
+ %cond = icmp sgt i32 %i1, -1
+ %res = select i1 %cond, double %a, double %b
+ ret double %res
+}
+
+; Check that <= -1 becomes < 0.
+define double @f19(double %a, double %b, i32 %i1) {
+; CHECK-LABEL: f19:
+; CHECK: cijl %r2, 0
+; CHECK: ldr %f0, %f2
+; CHECK: br %r14
+ %cond = icmp sle i32 %i1, -1
+ %res = select i1 %cond, double %a, double %b
+ ret double %res
+}
Modified: llvm/trunk/test/CodeGen/SystemZ/int-cmp-11.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/SystemZ/int-cmp-11.ll?rev=187571&r1=187570&r2=187571&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/SystemZ/int-cmp-11.ll (original)
+++ llvm/trunk/test/CodeGen/SystemZ/int-cmp-11.ll Thu Aug 1 05:29:45 2013
@@ -16,7 +16,7 @@ define double @f1(double %a, double %b,
; Check comparisons with 1.
define double @f2(double %a, double %b, i64 %i1) {
; CHECK-LABEL: f2:
-; CHECK: cgijl %r2, 1
+; CHECK: cgijle %r2, 0
; CHECK: ldr %f0, %f2
; CHECK: br %r14
%cond = icmp slt i64 %i1, 1
Modified: llvm/trunk/test/CodeGen/SystemZ/int-cmp-22.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/SystemZ/int-cmp-22.ll?rev=187571&r1=187570&r2=187571&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/SystemZ/int-cmp-22.ll (original)
+++ llvm/trunk/test/CodeGen/SystemZ/int-cmp-22.ll Thu Aug 1 05:29:45 2013
@@ -18,8 +18,8 @@ define double @f1(double %a, double %b,
; Check comparisons with 1.
define double @f2(double %a, double %b, i16 *%ptr) {
; CHECK-LABEL: f2:
-; CHECK: chhsi 0(%r2), 1
-; CHECK-NEXT: jl
+; CHECK: chhsi 0(%r2), 0
+; CHECK-NEXT: jle
; CHECK: ldr %f0, %f2
; CHECK: br %r14
%val = load i16 *%ptr
Modified: llvm/trunk/test/CodeGen/SystemZ/int-cmp-32.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/SystemZ/int-cmp-32.ll?rev=187571&r1=187570&r2=187571&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/SystemZ/int-cmp-32.ll (original)
+++ llvm/trunk/test/CodeGen/SystemZ/int-cmp-32.ll Thu Aug 1 05:29:45 2013
@@ -18,8 +18,8 @@ define double @f1(double %a, double %b,
; Check ordered comparisons with 1.
define double @f2(double %a, double %b, i32 *%ptr) {
; CHECK-LABEL: f2:
-; CHECK: chsi 0(%r2), 1
-; CHECK-NEXT: jl
+; CHECK: chsi 0(%r2), 0
+; CHECK-NEXT: jle
; CHECK: ldr %f0, %f2
; CHECK: br %r14
%val = load i32 *%ptr
Modified: llvm/trunk/test/CodeGen/SystemZ/int-cmp-34.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/SystemZ/int-cmp-34.ll?rev=187571&r1=187570&r2=187571&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/SystemZ/int-cmp-34.ll (original)
+++ llvm/trunk/test/CodeGen/SystemZ/int-cmp-34.ll Thu Aug 1 05:29:45 2013
@@ -18,8 +18,8 @@ define double @f1(double %a, double %b,
; Check ordered comparisons with 1.
define double @f2(double %a, double %b, i64 *%ptr) {
; CHECK-LABEL: f2:
-; CHECK: cghsi 0(%r2), 1
-; CHECK-NEXT: jl
+; CHECK: cghsi 0(%r2), 0
+; CHECK-NEXT: jle
; CHECK: ldr %f0, %f2
; CHECK: br %r14
%val = load i64 *%ptr
More information about the llvm-commits
mailing list