llvm.org GIT mirror llvm / dbdbe63
Merging r233153 and r233584: ------------------------------------------------------------------------ r233153 | probinson | 2015-03-24 17:10:24 -0700 (Tue, 24 Mar 2015) | 7 lines 'optnone' should not disable DAG combiner. Reverts the code change from r221168 and the relevant test. It was a mistake to disable the combiner, and based on the ultimate definition of 'optnone' we shouldn't have considered the test case as failing in the first place. ------------------------------------------------------------------------ r233584 | probinson | 2015-03-30 12:37:44 -0700 (Mon, 30 Mar 2015) | 9 lines Verify 'optnone' can run DAG combiner when appropriate. Adds a test to verify the behavior that r233153 restored: 'optnone' does not spuriously disable the DAG combiner, and in fact there are cases where the DAG combiner must run (even at -O0 or 'optnone') in order for codegen to succeed. Differential Revision: http://reviews.llvm.org/D8614 ------------------------------------------------------------------------ git-svn-id: https://llvm.org/svn/llvm-project/llvm/branches/release_36@233871 91177308-0d34-0410-b5e6-96231b3b80d8 Paul Robinson 5 years ago
3 changed file(s) with 73 addition(s) and 42 deletion(s). Raw diff Collapse all Expand all
11591159 LegalOperations = Level >= AfterLegalizeVectorOps;
11601160 LegalTypes = Level >= AfterLegalizeTypes;
11611161
1162 // Early exit if this basic block is in an optnone function.
1163 AttributeSet FnAttrs =
1164 DAG.getMachineFunction().getFunction()->getAttributes();
1165 if (FnAttrs.hasAttribute(AttributeSet::FunctionIndex,
1166 Attribute::OptimizeNone))
1167 return;
1168
11691162 // Add all the dag nodes to the worklist.
11701163 for (SelectionDAG::allnodes_iterator I = DAG.allnodes_begin(),
11711164 E = DAG.allnodes_end(); I != E; ++I)
0 ; RUN: llc < %s -mtriple=x86_64-pc-win32 -O0 -mattr=+avx | FileCheck %s
1
2 ; Background:
3 ; If fast-isel bails out to normal selection, then the DAG combiner will run,
4 ; even at -O0. In principle this should not happen (those are optimizations,
5 ; and we said -O0) but as a practical matter there are some instruction
6 ; selection patterns that depend on the legalizations and transforms that the
7 ; DAG combiner does.
8 ;
9 ; The 'optnone' attribute implicitly sets -O0 and fast-isel for the function.
10 ; The DAG combiner was disabled for 'optnone' (but not -O0) by r221168, then
11 ; re-enabled in r233153 because of problems with instruction selection patterns
12 ; mentioned above. (Note: because 'optnone' is supposed to match -O0, r221168
13 ; really should have disabled the combiner for both.)
14 ;
15 ; If instruction selection eventually becomes smart enough to run without DAG
16 ; combiner, then the combiner can be turned off for -O0 (not just 'optnone')
17 ; and this test can go away. (To be replaced by a different test that verifies
18 ; the DAG combiner does *not* run at -O0 or for 'optnone' functions.)
19 ;
20 ; In the meantime, this test wants to make sure the combiner stays enabled for
21 ; 'optnone' functions, just as it is for -O0.
22
23
24 ; The test cases @foo[WithOptnone] prove that the same DAG combine happens
25 ; with -O0 and with 'optnone' set. To prove this, we use a Windows triple to
26 ; cause fast-isel to bail out (because something about the calling convention
27 ; is not handled in fast-isel). Then we have a repeated fadd that can be
28 ; combined into an fmul. We show that this happens in both the non-optnone
29 ; function and the optnone function.
30
31 define float @foo(float %x) #0 {
32 entry:
33 %add = fadd fast float %x, %x
34 %add1 = fadd fast float %add, %x
35 ret float %add1
36 }
37
38 ; CHECK-LABEL: @foo
39 ; CHECK-NOT: add
40 ; CHECK: mul
41 ; CHECK-NEXT: ret
42
43 define float @fooWithOptnone(float %x) #1 {
44 entry:
45 %add = fadd fast float %x, %x
46 %add1 = fadd fast float %add, %x
47 ret float %add1
48 }
49
50 ; CHECK-LABEL: @fooWithOptnone
51 ; CHECK-NOT: add
52 ; CHECK: mul
53 ; CHECK-NEXT: ret
54
55
56 ; The test case @bar is derived from an instruction selection failure case
57 ; that was solved by r233153. It depends on -mattr=+avx.
58 ; Really all we're trying to prove is that it doesn't crash any more.
59
60 @id84 = common global <16 x i32> zeroinitializer, align 64
61
62 define void @bar() #1 {
63 entry:
64 %id83 = alloca <16 x i8>, align 16
65 %0 = load <16 x i32>* @id84, align 64
66 %conv = trunc <16 x i32> %0 to <16 x i8>
67 store <16 x i8> %conv, <16 x i8>* %id83, align 16
68 ret void
69 }
70
71 attributes #0 = { "unsafe-fp-math"="true" }
72 attributes #1 = { noinline optnone "unsafe-fp-math"="true" }
+0
-35
test/CodeGen/X86/fastmath-optnone.ll less more
None ; RUN: llc < %s -mcpu=corei7 -march=x86-64 -mattr=+sse2 | FileCheck %s
1 ; Verify that floating-point operations inside 'optnone' functions
2 ; are not optimized even if unsafe-fp-math is set.
3
4 define float @foo(float %x) #0 {
5 entry:
6 %add = fadd fast float %x, %x
7 %add1 = fadd fast float %add, %x
8 ret float %add1
9 }
10
11 ; CHECK-LABEL: @foo
12 ; CHECK-NOT: add
13 ; CHECK: mul
14 ; CHECK-NOT: add
15 ; CHECK: ret
16
17 define float @fooWithOptnone(float %x) #1 {
18 entry:
19 %add = fadd fast float %x, %x
20 %add1 = fadd fast float %add, %x
21 ret float %add1
22 }
23
24 ; CHECK-LABEL: @fooWithOptnone
25 ; CHECK-NOT: mul
26 ; CHECK: add
27 ; CHECK-NOT: mul
28 ; CHECK: add
29 ; CHECK-NOT: mul
30 ; CHECK: ret
31
32
33 attributes #0 = { "unsafe-fp-math"="true" }
34 attributes #1 = { noinline optnone "unsafe-fp-math"="true" }