Make assignTemp_ less pessimistic
authorJohan Tibell <johan.tibell@gmail.com>
Thu, 19 May 2011 15:34:20 +0000 (17:34 +0200)
committerJohan Tibell <johan.tibell@gmail.com>
Mon, 30 May 2011 18:12:05 +0000 (20:12 +0200)
assignTemp_ is intended to make sure that the expression gets assigned
to a temporary in case that's needed in order to avoid a register
getting trashed due to a function call.

compiler/codeGen/CgUtils.hs

index 4df7c77..63d99a6 100644 (file)
@@ -601,13 +601,17 @@ assignTemp e
                            ; stmtC (CmmAssign (CmmLocal reg) e)
                            ; return (CmmReg (CmmLocal reg)) }
 
--- | Assign the expression to a temporary register and return an
--- expression referring to this register.
+-- | If the expression is trivial and doesn't refer to a global
+-- register, return it.  Otherwise, assign the expression to a
+-- temporary register and return an expression referring to this
+-- register.
 assignTemp_ :: CmmExpr -> FCode CmmExpr
-assignTemp_ e = do
-    reg <- newTemp (cmmExprType e)
-    stmtC (CmmAssign (CmmLocal reg) e)
-    return (CmmReg (CmmLocal reg))
+assignTemp_ e
+    | isTrivialCmmExpr e && hasNoGlobalRegs e = return e
+    | otherwise = do
+        reg <- newTemp (cmmExprType e)
+        stmtC (CmmAssign (CmmLocal reg) e)
+        return (CmmReg (CmmLocal reg))
 
 newTemp :: CmmType -> FCode LocalReg
 newTemp rep = do { uniq <- newUnique; return (LocalReg uniq rep) }