[llvm-commits] CVS: llvm/lib/Target/PowerPC/PPC32ISelPattern.cpp

Chris Lattner lattner at cs.uiuc.edu
Sun Aug 21 10:41:23 PDT 2005



Changes in directory llvm/lib/Target/PowerPC:

PPC32ISelPattern.cpp updated: 1.156 -> 1.157
---
Log message:

If the false value for a select_cc is really simple (has no inputs), evaluate
it in the block.  This codegens:

int %test(bool %c) {
        %retval = select bool %c, int 17, int 1 
        ret int %retval
}

as:

_test:
        rlwinm r2, r3, 0, 31, 31
        li r2, 17
        cmpwi cr0, r3, 0
        bne .LBB_test_2 ; 
.LBB_test_1:    ; 
        li r2, 1
.LBB_test_2:    ; 
        or r3, r2, r2
        blr

instead of:

_test:
        rlwinm r2, r3, 0, 31, 31
        li r2, 17
        li r4, 1
        cmpwi cr0, r3, 0
        bne .LBB_test_2 ; 
.LBB_test_1:    ; 
        or r2, r4, r4
.LBB_test_2:    ; 
        or r3, r2, r2
        blr

... which is one fewer instruction.  The savings are more significant for 
global address and constantfp nodes.



---
Diffs of the changes:  (+16 -1)

 PPC32ISelPattern.cpp |   17 ++++++++++++++++-
 1 files changed, 16 insertions(+), 1 deletion(-)


Index: llvm/lib/Target/PowerPC/PPC32ISelPattern.cpp
diff -u llvm/lib/Target/PowerPC/PPC32ISelPattern.cpp:1.156 llvm/lib/Target/PowerPC/PPC32ISelPattern.cpp:1.157
--- llvm/lib/Target/PowerPC/PPC32ISelPattern.cpp:1.156	Thu Aug 18 22:42:28 2005
+++ llvm/lib/Target/PowerPC/PPC32ISelPattern.cpp	Sun Aug 21 12:41:11 2005
@@ -1675,7 +1675,16 @@
     // selecting it in the fallthrough basic block rather than here, which
     // increases register pressure.
     unsigned TrueValue = SelectExpr(N.getOperand(2));
-    unsigned FalseValue = SelectExpr(N.getOperand(3));
+    unsigned FalseValue;
+
+    // If the false value is simple enough, evaluate it inline in the false
+    // block.
+    if (isa<ConstantSDNode>(N.getOperand(3)) ||
+        isa<ConstantFPSDNode>(N.getOperand(3)) ||
+        isa<GlobalAddressSDNode>(N.getOperand(3)))
+      FalseValue = 0;
+    else
+      FalseValue = SelectExpr(N.getOperand(3));
     unsigned CCReg = SelectCC(N.getOperand(0), N.getOperand(1), CC);
     Opc = getBCCForSetCC(CC);
     
@@ -1706,6 +1715,12 @@
     //   %FalseValue = ...
     //   # fallthrough to sinkMBB
     BB = copy0MBB;
+
+    // If the false value is simple enough, evaluate it here, to avoid it being
+    // evaluated on the true edge.
+    if (FalseValue == 0)
+      FalseValue = SelectExpr(N.getOperand(3));
+
     // Update machine-CFG edges
     BB->addSuccessor(sinkMBB);
 






More information about the llvm-commits mailing list