llvm.org GIT mirror llvm / 514eb49
Merging r228656: ------------------------------------------------------------------------ r228656 | chandlerc | 2015-02-09 18:25:56 -0800 (Mon, 09 Feb 2015) | 16 lines [x86] Fix PR22524: the DAG combiner was incorrectly handling illegal nodes when folding bitcasts of constants. We can't fold things and then check after-the-fact whether it was legal. Once we have formed the DAG node, arbitrary other nodes may have been collapsed to it. There is no easy way to go back. Instead, we need to test for the specific folding cases we're interested in and ensure those are legal first. This could in theory make this less powerful for bitcasting from an integer to some vector type, but AFAICT, that can't actually happen in the SDAG so its fine. Now, we *only* whitelist specific int->fp and fp->int bitcasts for post-legalization folding. I've added the test case from the PR. (Also as a note, this does not appear to be in 3.6, no backport needed) ------------------------------------------------------------------------ git-svn-id: https://llvm.org/svn/llvm-project/llvm/branches/release_36@228787 91177308-0d34-0410-b5e6-96231b3b80d8 Hans Wennborg 5 years ago
2 changed file(s) with 44 addition(s) and 13 deletion(s). Raw diff Collapse all Expand all
65436543
65446544 // If the input is a constant, let getNode fold it.
65456545 if (isa(N0) || isa(N0)) {
6546 SDValue Res = DAG.getNode(ISD::BITCAST, SDLoc(N), VT, N0);
6547 if (Res.getNode() != N) {
6548 if (!LegalOperations ||
6549 TLI.isOperationLegal(Res.getNode()->getOpcode(), VT))
6550 return Res;
6551
6552 // Folding it resulted in an illegal node, and it's too late to
6553 // do that. Clean up the old node and forego the transformation.
6554 // Ideally this won't happen very often, because instcombine
6555 // and the earlier dagcombine runs (where illegal nodes are
6556 // permitted) should have folded most of them already.
6557 deleteAndRecombine(Res.getNode());
6558 }
6546 // If we can't allow illegal operations, we need to check that this is just
6547 // a fp -> int or int -> conversion and that the resulting operation will
6548 // be legal.
6549 if (!LegalOperations ||
6550 (isa(N0) && VT.isFloatingPoint() && !VT.isVector() &&
6551 TLI.isOperationLegal(ISD::ConstantFP, VT)) ||
6552 (isa(N0) && VT.isInteger() && !VT.isVector() &&
6553 TLI.isOperationLegal(ISD::Constant, VT)))
6554 return DAG.getNode(ISD::BITCAST, SDLoc(N), VT, N0);
65596555 }
65606556
65616557 // (conv (conv x, t1), t2) -> (conv x, t2)
0 ; RUN: llc < %s | FileCheck %s
1
2 target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
3 target triple = "x86_64-unknown-unknown"
4
5 define void @PR22524({ float, float }* %arg) {
6 ; Check that we can materialize the zero constants we store in two places here,
7 ; and at least form a legal store of the floating point value at the end.
8 ; The DAG combiner at one point contained bugs that given enough permutations
9 ; would incorrectly form an illegal operation for the last of these stores when
10 ; it folded it to a zero too late to legalize the zero store operation. If this
11 ; ever starts forming a zero store instead of movss, the test case has stopped
12 ; being useful.
13 ;
14 ; CHECK-LABEL: PR22524:
15 entry:
16 %0 = getelementptr inbounds { float, float }* %arg, i32 0, i32 1
17 store float 0.000000e+00, float* %0, align 4
18 ; CHECK: movl $0, 4(%rdi)
19
20 %1 = getelementptr inbounds { float, float }* %arg, i64 0, i32 0
21 %2 = bitcast float* %1 to i64*
22 %3 = load i64* %2, align 8
23 %4 = trunc i64 %3 to i32
24 %5 = lshr i64 %3, 32
25 %6 = trunc i64 %5 to i32
26 %7 = bitcast i32 %6 to float
27 %8 = fmul float %7, 0.000000e+00
28 %9 = bitcast float* %1 to i32*
29 store i32 %6, i32* %9, align 4
30 ; CHECK: movl $0, (%rdi)
31 store float %8, float* %0, align 4
32 ; CHECK: movss %{{.*}}, 4(%rdi)
33 ret void
34 }