[llvm] r356869 - [X86] When selecting (x << C1) op C2 as (x op (C2>>C1)) << C1, use the operation VT for the target constant.

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Sun Mar 24 23:53:45 PDT 2019


Author: ctopper
Date: Sun Mar 24 23:53:45 2019
New Revision: 356869

URL: http://llvm.org/viewvc/llvm-project?rev=356869&view=rev
Log:
[X86] When selecting (x << C1) op C2 as (x op (C2>>C1)) << C1, use the operation VT for the target constant.

Normally when the nodes we use here(AND32ri8 for example) are selected their
immediates are just converted from ConstantSDNode to TargetConstantSDNode
without changing VT from the original operation VT. So we should still be
emitting them with the operation VT.

Theoretically this could expose more accurate opportunities for CSE.

Modified:
    llvm/trunk/lib/Target/X86/X86ISelDAGToDAG.cpp

Modified: llvm/trunk/lib/Target/X86/X86ISelDAGToDAG.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86ISelDAGToDAG.cpp?rev=356869&r1=356868&r2=356869&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/X86ISelDAGToDAG.cpp (original)
+++ llvm/trunk/lib/Target/X86/X86ISelDAGToDAG.cpp Sun Mar 24 23:53:45 2019
@@ -3561,7 +3561,8 @@ void X86DAGToDAGISel::Select(SDNode *Nod
     }
 
     // Emit the smaller op and the shift.
-    SDValue NewCst = CurDAG->getTargetConstant(Val >> ShlVal, dl, CstVT);
+    // Even though we shrink the constant, the VT should match the operation VT.
+    SDValue NewCst = CurDAG->getTargetConstant(Val >> ShlVal, dl, NVT);
     SDNode *New = CurDAG->getMachineNode(Op, dl, NVT, N0->getOperand(0),NewCst);
     if (ShlVal == 1)
       CurDAG->SelectNodeTo(Node, AddOp, NVT, SDValue(New, 0),




More information about the llvm-commits mailing list