nv50/ir: clean up saturated values immediately
authorIlia Mirkin <imirkin@alum.mit.edu>
Sat, 12 Aug 2017 17:43:34 +0000 (13:43 -0400)
committerIlia Mirkin <imirkin@alum.mit.edu>
Sat, 12 Aug 2017 18:49:08 +0000 (14:49 -0400)
Since we don't iterate to a fixed point, we can end up in situations
where we have a SAT instruction + a long immediate. This is not legal.
However since it's immediately computable, just run unary straight away
to handle the situation.

Fixes: 24a799ad35a82 ("nv50/ir: fix ConstantFolding with saturation")
Reported-by: Tobias Klausmann <tobias.johannes.klausmann@mni.thm.de>
Signed-off-by: Ilia Mirkin <imirkin@alum.mit.edu>
Cc: mesa-stable@lists.freedesktop.org
src/gallium/drivers/nouveau/codegen/nv50_ir_peephole.cpp

index cfc0dfc53cf63f5d2f1588561a1427ff5fa7bb79..7e4e193e3d27d08141c4ba7d533d9996c72de277 100644 (file)
@@ -727,7 +727,9 @@ ConstantFolding::expr(Instruction *i,
       // Leave PFETCH alone... we just folded its 2 args into 1.
       break;
    default:
-      i->op = i->saturate ? OP_SAT : OP_MOV; /* SAT handled by unary() */
+      i->op = i->saturate ? OP_SAT : OP_MOV;
+      if (i->saturate)
+         unary(i, *i->getSrc(0)->asImm());
       break;
    }
    i->subOp = 0;
@@ -1513,8 +1515,11 @@ ConstantFolding::opnd(Instruction *i, ImmediateValue &imm0, int s)
    // This can get left behind some of the optimizations which simplify
    // saturatable values.
    if (newi->op == OP_MOV && newi->saturate) {
+      ImmediateValue tmp;
       newi->saturate = 0;
       newi->op = OP_SAT;
+      if (newi->src(0).getImmediate(tmp))
+         unary(newi, tmp);
    }
 
    if (newi->op != op)