llvm.org GIT mirror llvm / f55d26e
Implement mulo x, 2 -> addo x, x in DAGCombiner. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@131800 91177308-0d34-0410-b5e6-96231b3b80d8 Benjamin Kramer 8 years ago
2 changed file(s) with 48 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
164164 SDValue visitMULHS(SDNode *N);
165165 SDValue visitSMUL_LOHI(SDNode *N);
166166 SDValue visitUMUL_LOHI(SDNode *N);
167 SDValue visitSMULO(SDNode *N);
168 SDValue visitUMULO(SDNode *N);
167169 SDValue visitSDIVREM(SDNode *N);
168170 SDValue visitUDIVREM(SDNode *N);
169171 SDValue visitAND(SDNode *N);
10461048 case ISD::MULHS: return visitMULHS(N);
10471049 case ISD::SMUL_LOHI: return visitSMUL_LOHI(N);
10481050 case ISD::UMUL_LOHI: return visitUMUL_LOHI(N);
1051 case ISD::SMULO: return visitSMULO(N);
1052 case ISD::UMULO: return visitUMULO(N);
10491053 case ISD::SDIVREM: return visitSDIVREM(N);
10501054 case ISD::UDIVREM: return visitUDIVREM(N);
10511055 case ISD::AND: return visitAND(N);
21762180 return SDValue();
21772181 }
21782182
2183 SDValue DAGCombiner::visitSMULO(SDNode *N) {
2184 // (smulo x, 2) -> (saddo x, x)
2185 if (ConstantSDNode *C2 = dyn_cast(N->getOperand(1)))
2186 if (C2->getAPIntValue() == 2)
2187 return DAG.getNode(ISD::SADDO, N->getDebugLoc(), N->getVTList(),
2188 N->getOperand(0), N->getOperand(0));
2189
2190 return SDValue();
2191 }
2192
2193 SDValue DAGCombiner::visitUMULO(SDNode *N) {
2194 // (umulo x, 2) -> (uaddo x, x)
2195 if (ConstantSDNode *C2 = dyn_cast(N->getOperand(1)))
2196 if (C2->getAPIntValue() == 2)
2197 return DAG.getNode(ISD::UADDO, N->getDebugLoc(), N->getVTList(),
2198 N->getOperand(0), N->getOperand(0));
2199
2200 return SDValue();
2201 }
2202
21792203 SDValue DAGCombiner::visitSDIVREM(SDNode *N) {
21802204 SDValue Res = SimplifyNodeWithTwoResults(N, ISD::SDIV, ISD::SREM);
21812205 if (Res.getNode()) return Res;
1111 ; CHECK: movzbl %al, %eax
1212 ; CHECK: ret
1313 }
14
15 define i32 @test2(i32 %a, i32 %b) nounwind readnone {
16 entry:
17 %tmp0 = add i32 %b, %a
18 %tmp1 = call { i32, i1 } @llvm.umul.with.overflow.i32(i32 %tmp0, i32 2)
19 %tmp2 = extractvalue { i32, i1 } %tmp1, 0
20 ret i32 %tmp2
21 ; CHECK: test2:
22 ; CHECK: addl
23 ; CHECK-NEXT: addl
24 ; CHECK-NEXT: ret
25 }
26
27 define i32 @test3(i32 %a, i32 %b) nounwind readnone {
28 entry:
29 %tmp0 = add i32 %b, %a
30 %tmp1 = call { i32, i1 } @llvm.umul.with.overflow.i32(i32 %tmp0, i32 4)
31 %tmp2 = extractvalue { i32, i1 } %tmp1, 0
32 ret i32 %tmp2
33 ; CHECK: test3:
34 ; CHECK: addl
35 ; CHECK: mull
36 ; CHECK-NEXT: ret
37 }