R600/SI: swap operands if it helps folding
authorChristian Konig <christian.koenig@amd.com>
Tue, 26 Feb 2013 17:52:36 +0000 (17:52 +0000)
committerChristian Konig <christian.koenig@amd.com>
Tue, 26 Feb 2013 17:52:36 +0000 (17:52 +0000)
Signed-off-by: Christian König <christian.koenig@amd.com>
Reviewed-by: Tom Stellard <thomas.stellard@amd.com>
llvm-svn: 176103

llvm/lib/Target/R600/SIISelLowering.cpp

index bf1f3bf..da30c07 100644 (file)
@@ -545,8 +545,22 @@ SDNode *SITargetLowering::PostISelFolding(MachineSDNode *Node,
 
     // Is this a VSrc or SSrc operand ?
     unsigned RegClass = Desc->OpInfo[Op].RegClass;
-    if (!isVSrc(RegClass) && !isSSrc(RegClass))
+    if (!isVSrc(RegClass) && !isSSrc(RegClass)) {
+
+      if (i == 1 && Desc->isCommutable() &&
+          fitsRegClass(DAG, Ops[0], RegClass) &&
+          foldImm(Ops[1], Immediate, ScalarSlotUsed)) {
+
+        assert(isVSrc(Desc->OpInfo[NumDefs].RegClass) ||
+               isSSrc(Desc->OpInfo[NumDefs].RegClass));
+
+        // Swap commutable operands
+        SDValue Tmp = Ops[1];
+        Ops[1] = Ops[0];
+        Ops[0] = Tmp;
+      }
       continue;
+    }
 
     // Try to fold the immediates
     if (!foldImm(Ops[i], Immediate, ScalarSlotUsed)) {