[llvm] r196579 - [SystemZ] Extend the use of C(L)GFR

Richard Sandiford rsandifo at linux.vnet.ibm.com
Fri Dec 6 01:56:50 PST 2013


Author: rsandifo
Date: Fri Dec  6 03:56:50 2013
New Revision: 196579

URL: http://llvm.org/viewvc/llvm-project?rev=196579&view=rev
Log:
[SystemZ] Extend the use of C(L)GFR

instcombine prefers to put extended operands first, so this patch
handles that case for C(L)GFR.

Modified:
    llvm/trunk/lib/Target/SystemZ/SystemZISelLowering.cpp
    llvm/trunk/test/CodeGen/SystemZ/int-cmp-05.ll
    llvm/trunk/test/CodeGen/SystemZ/int-cmp-06.ll

Modified: llvm/trunk/lib/Target/SystemZ/SystemZISelLowering.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/SystemZ/SystemZISelLowering.cpp?rev=196579&r1=196578&r2=196579&view=diff
==============================================================================
--- llvm/trunk/lib/Target/SystemZ/SystemZISelLowering.cpp (original)
+++ llvm/trunk/lib/Target/SystemZ/SystemZISelLowering.cpp Fri Dec  6 03:56:50 2013
@@ -1207,10 +1207,14 @@ static bool shouldSwapCmpOperands(SDValu
   if (COp1 && COp1->getZExtValue() == 0)
     return false;
 
+  // Also keep natural memory operands second if the loaded value is
+  // only used here.  Several comparisons have memory forms.
+  if (isNaturalMemoryOperand(Op1, ICmpType) && Op1.hasOneUse())
+    return false;
+
   // Look for cases where Cmp0 is a single-use load and Cmp1 isn't.
   // In that case we generally prefer the memory to be second.
-  if ((isNaturalMemoryOperand(Op0, ICmpType) && Op0.hasOneUse()) &&
-      !(isNaturalMemoryOperand(Op1, ICmpType) && Op1.hasOneUse())) {
+  if (isNaturalMemoryOperand(Op0, ICmpType) && Op0.hasOneUse()) {
     // The only exceptions are when the second operand is a constant and
     // we can use things like CHHSI.
     if (!COp1)
@@ -1227,6 +1231,19 @@ static bool shouldSwapCmpOperands(SDValu
       return false;
     return true;
   }
+
+  // Try to promote the use of CGFR and CLGFR.
+  unsigned Opcode0 = Op0.getOpcode();
+  if (ICmpType != SystemZICMP::UnsignedOnly && Opcode0 == ISD::SIGN_EXTEND)
+    return true;
+  if (ICmpType != SystemZICMP::SignedOnly && Opcode0 == ISD::ZERO_EXTEND)
+    return true;
+  if (ICmpType != SystemZICMP::SignedOnly &&
+      Opcode0 == ISD::AND &&
+      Op0.getOperand(1).getOpcode() == ISD::Constant &&
+      cast<ConstantSDNode>(Op0.getOperand(1))->getZExtValue() == 0xffffffff)
+    return true;
+
   return false;
 }
 

Modified: llvm/trunk/test/CodeGen/SystemZ/int-cmp-05.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/SystemZ/int-cmp-05.ll?rev=196579&r1=196578&r2=196579&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/SystemZ/int-cmp-05.ll (original)
+++ llvm/trunk/test/CodeGen/SystemZ/int-cmp-05.ll Fri Dec  6 03:56:50 2013
@@ -291,9 +291,22 @@ define i64 @f15(i32 *%ptr0) {
   ret i64 %sel9
 }
 
-; Check the comparison can be reversed if that allows CGF to be used.
-define double @f16(double %a, double %b, i64 %i2, i32 *%ptr) {
+; Check the comparison can be reversed if that allows CGFR to be used.
+define double @f16(double %a, double %b, i64 %i1, i32 %unext) {
 ; CHECK-LABEL: f16:
+; CHECK: cgfr %r2, %r3
+; CHECK-NEXT: jh
+; CHECK: ldr %f0, %f2
+; CHECK: br %r14
+  %i2 = sext i32 %unext to i64
+  %cond = icmp slt i64 %i2, %i1
+  %res = select i1 %cond, double %a, double %b
+  ret double %res
+}
+
+; Likewise CGF.
+define double @f17(double %a, double %b, i64 %i2, i32 *%ptr) {
+; CHECK-LABEL: f17:
 ; CHECK: cgf %r2, 0(%r3)
 ; CHECK-NEXT: jh {{\.L.*}}
 ; CHECK: ldr %f0, %f2

Modified: llvm/trunk/test/CodeGen/SystemZ/int-cmp-06.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/SystemZ/int-cmp-06.ll?rev=196579&r1=196578&r2=196579&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/SystemZ/int-cmp-06.ll (original)
+++ llvm/trunk/test/CodeGen/SystemZ/int-cmp-06.ll Fri Dec  6 03:56:50 2013
@@ -341,9 +341,35 @@ define i64 @f19(i32 *%ptr0) {
   ret i64 %sel9
 }
 
-; Check the comparison can be reversed if that allows CLGF to be used.
-define double @f20(double %a, double %b, i64 %i2, i32 *%ptr) {
+; Check the comparison can be reversed if that allows CLGFR to be used.
+define double @f20(double %a, double %b, i64 %i1, i32 %unext) {
 ; CHECK-LABEL: f20:
+; CHECK: clgfr %r2, %r3
+; CHECK-NEXT: jh
+; CHECK: ldr %f0, %f2
+; CHECK: br %r14
+  %i2 = zext i32 %unext to i64
+  %cond = icmp ult i64 %i2, %i1
+  %res = select i1 %cond, double %a, double %b
+  ret double %res
+}
+
+; ...and again with the AND representation.
+define double @f21(double %a, double %b, i64 %i1, i64 %unext) {
+; CHECK-LABEL: f21:
+; CHECK: clgfr %r2, %r3
+; CHECK-NEXT: jh
+; CHECK: ldr %f0, %f2
+; CHECK: br %r14
+  %i2 = and i64 %unext, 4294967295
+  %cond = icmp ult i64 %i2, %i1
+  %res = select i1 %cond, double %a, double %b
+  ret double %res
+}
+
+; Check the comparison can be reversed if that allows CLGF to be used.
+define double @f22(double %a, double %b, i64 %i2, i32 *%ptr) {
+; CHECK-LABEL: f22:
 ; CHECK: clgf %r2, 0(%r3)
 ; CHECK-NEXT: jh {{\.L.*}}
 ; CHECK: ldr %f0, %f2





More information about the llvm-commits mailing list