[PATCH] D26449: DAGCombiner: fix combine of trunc and select
Asaf Badouh via llvm-commits
llvm-commits at lists.llvm.org
Thu Nov 10 06:06:22 PST 2016
AsafBadouh added a reviewer: spatel.
AsafBadouh updated this revision to Diff 77475.
AsafBadouh added a comment.
+ Sanjay
fixes pr29002
update the test case using the example in pr29002
https://llvm.org/bugs/show_bug.cgi?id=29002
Repository:
rL LLVM
https://reviews.llvm.org/D26449
Files:
lib/CodeGen/SelectionDAG/DAGCombiner.cpp
test/CodeGen/X86/select.ll
Index: lib/CodeGen/SelectionDAG/DAGCombiner.cpp
===================================================================
--- lib/CodeGen/SelectionDAG/DAGCombiner.cpp
+++ lib/CodeGen/SelectionDAG/DAGCombiner.cpp
@@ -7305,7 +7305,7 @@
}
// trunc (select c, a, b) -> select c, (trunc a), (trunc b)
- if (N0.getOpcode() == ISD::SELECT) {
+ if (N0.getOpcode() == ISD::SELECT && N0.hasOneUse()) {
EVT SrcVT = N0.getValueType();
if ((!LegalOperations || TLI.isOperationLegal(ISD::SELECT, SrcVT)) &&
TLI.isTruncateFree(SrcVT, VT)) {
Index: test/CodeGen/X86/select.ll
===================================================================
--- test/CodeGen/X86/select.ll
+++ test/CodeGen/X86/select.ll
@@ -515,6 +515,28 @@
ret i32 %tmp2
}
+define void @clamp(float* %src, i16* %dst) {
+; verify that 2 select will not became 3 cmovs
+; fixes pr29002
+entry:
+; CHECK-LABEL: clamp:
+; CHECK: ## BB#0:
+; CHECK: cmovlel
+; CHECK: cmovgew
+; CHECK-NOT: cmov
+; CHECK: retq
+ %ld = load float, float* %src, align 4
+ %mul = fmul float %ld, 3.276700e+04
+ %conv = fptosi float %mul to i32
+ %cmp = icmp sgt i32 %conv, 32767
+ %sel1 = select i1 %cmp, i32 32767, i32 %conv
+ %cmp2 = icmp slt i32 %sel1, -32768
+ %sel2 = select i1 %cmp2, i32 -32768, i32 %sel1
+ %conv6 = trunc i32 %sel2 to i16
+ store i16 %conv6, i16* %dst, align 2
+ ret void
+}
+
define void @test19() {
; This is a massive reduction of an llvm-stress test case that generates
; interesting chains feeding setcc and eventually a f32 select operation. This
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D26449.77475.patch
Type: text/x-patch
Size: 1589 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161110/011a2e33/attachment.bin>
More information about the llvm-commits
mailing list