[PATCH] D29587: [DAGCombiner] mulhi + 1 never overflow.
Amaury SECHET via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Mar 1 15:56:11 PST 2017
This revision was automatically updated to reflect the committed changes.
Closed by commit rL296711: [DAGCombiner] mulhi + 1 never overflow. (authored by deadalnix).
Changed prior to commit:
https://reviews.llvm.org/D29587?vs=90250&id=90251#toc
Repository:
rL LLVM
https://reviews.llvm.org/D29587
Files:
llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
llvm/trunk/test/CodeGen/X86/overflow.ll
Index: llvm/trunk/test/CodeGen/X86/overflow.ll
===================================================================
--- llvm/trunk/test/CodeGen/X86/overflow.ll
+++ llvm/trunk/test/CodeGen/X86/overflow.ll
@@ -50,10 +50,8 @@
; X64-NEXT: movq %rdi, %rax
; X64-NEXT: mulq %rsi
; X64-NEXT: andl $1, %ecx
-; X64-NEXT: addq %rdx, %rcx
-; X64-NEXT: sbbq %rdx, %rdx
-; X64-NEXT: andl $1, %edx
-; X64-NEXT: movq %rcx, %rax
+; X64-NEXT: leaq (%rcx,%rdx), %rax
+; X64-NEXT: xorl %edx, %edx
; X64-NEXT: retq
%1 = zext i64 %a to i128
%2 = zext i64 %b to i128
Index: llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
===================================================================
--- llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
+++ llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
@@ -2775,6 +2775,19 @@
return OFK_Never;
}
+ // mulhi + 1 never overflow
+ if (N0.getOpcode() == ISD::UMUL_LOHI && N0.getResNo() == 1 &&
+ (~N1Zero & 0x01) == ~N1Zero)
+ return OFK_Never;
+
+ if (N1.getOpcode() == ISD::UMUL_LOHI && N1.getResNo() == 1) {
+ APInt N0Zero, N0One;
+ computeKnownBits(N0, N0Zero, N0One);
+
+ if ((~N0Zero & 0x01) == ~N0Zero)
+ return OFK_Never;
+ }
+
return OFK_Sometime;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D29587.90251.patch
Type: text/x-patch
Size: 1272 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170301/3925fc58/attachment.bin>
More information about the llvm-commits
mailing list