]> granicus.if.org Git - llvm/commitdiff
[DAGCombiner] Fix a crash visiting `AND` nodes.
authorDavide Italiano <davide@freebsd.org>
Fri, 28 Oct 2016 23:55:32 +0000 (23:55 +0000)
committerDavide Italiano <davide@freebsd.org>
Fri, 28 Oct 2016 23:55:32 +0000 (23:55 +0000)
Instead of asserting that the shift count is != 0 we just bail out
as it's not profitable trying to optimize a node which will be
removed anyway.

Differential Revision:  https://reviews.llvm.org/D26098

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@285480 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/SelectionDAG/DAGCombiner.cpp
test/CodeGen/X86/pr30813.s [new file with mode: 0644]

index 81fb69f517f5793e81d1093475eb73b25c29b27a..f5aeb8cb533131c62f131a69ec6613c34c81d04a 100644 (file)
@@ -3046,6 +3046,11 @@ SDValue DAGCombiner::visitANDLike(SDValue N0, SDValue N1,
         unsigned Size = VT.getSizeInBits();
         const APInt &AndMask = CAnd->getAPIntValue();
         unsigned ShiftBits = CShift->getZExtValue();
+
+        // Bail out, this node will probably disappear anyway.
+        if (ShiftBits == 0)
+          return SDValue();
+
         unsigned MaskBits = AndMask.countTrailingOnes();
         EVT HalfVT = EVT::getIntegerVT(*DAG.getContext(), Size / 2);
 
@@ -3064,7 +3069,7 @@ SDValue DAGCombiner::visitANDLike(SDValue N0, SDValue N1,
           // extended to handle extensions mixed in.
 
           SDValue SL(N0);
-          assert(ShiftBits != 0 && MaskBits <= Size);
+          assert(MaskBits <= Size);
 
           // Extracting the highest bit of the low half.
           EVT ShiftVT = TLI.getShiftAmountTy(HalfVT, DAG.getDataLayout());
diff --git a/test/CodeGen/X86/pr30813.s b/test/CodeGen/X86/pr30813.s
new file mode 100644 (file)
index 0000000..cc8726a
--- /dev/null
@@ -0,0 +1,20 @@
+       .text
+       .file   "/home/davide/work/llvm/test/CodeGen/X86/visitand-shift.ll"
+       .globl  patatino
+       .p2align        4, 0x90
+       .type   patatino,@function
+patatino:                               # @patatino
+       .cfi_startproc
+# BB#0:
+                                        # implicit-def: %RAX
+       movzwl  (%rax), %ecx
+       movl    %ecx, %eax
+                                        # implicit-def: %RDX
+       movq    %rax, (%rdx)
+       retq
+.Lfunc_end0:
+       .size   patatino, .Lfunc_end0-patatino
+       .cfi_endproc
+
+
+       .section        ".note.GNU-stack","",@progbits