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
This commit is contained in:
Paul Robinson committed 2015-04-02 00:15:35 +00:00
1 parent 0c05d9a265
commit dbdbe63b4a
3 files changed
+73 -42

No files matched your search

-7
View File
@@ -1160,13 +1160,6 @@ void DAGCombiner::Run(CombineLevel AtLevel) {
LegalOperations = Level >= AfterLegalizeVectorOps;
LegalTypes = Level >= AfterLegalizeTypes;
// Early exit if this basic block is in an optnone function.
AttributeSet FnAttrs =
DAG.getMachineFunction().getFunction()->getAttributes();
if (FnAttrs.hasAttribute(AttributeSet::FunctionIndex,
Attribute::OptimizeNone))
return;
// Add all the dag nodes to the worklist.
for (SelectionDAG::allnodes_iterator I = DAG.allnodes_begin(),
E = DAG.allnodes_end(); I != E; ++I)
+73
View File
@@ -0,0 +1,73 @@
; RUN: llc < %s -mtriple=x86_64-pc-win32 -O0 -mattr=+avx | FileCheck %s
; Background:
; If fast-isel bails out to normal selection, then the DAG combiner will run,
; even at -O0. In principle this should not happen (those are optimizations,
; and we said -O0) but as a practical matter there are some instruction
; selection patterns that depend on the legalizations and transforms that the
; DAG combiner does.
;
; The 'optnone' attribute implicitly sets -O0 and fast-isel for the function.
; The DAG combiner was disabled for 'optnone' (but not -O0) by r221168, then
; re-enabled in r233153 because of problems with instruction selection patterns
; mentioned above. (Note: because 'optnone' is supposed to match -O0, r221168
; really should have disabled the combiner for both.)
;
; If instruction selection eventually becomes smart enough to run without DAG
; combiner, then the combiner can be turned off for -O0 (not just 'optnone')
; and this test can go away. (To be replaced by a different test that verifies
; the DAG combiner does *not* run at -O0 or for 'optnone' functions.)
;
; In the meantime, this test wants to make sure the combiner stays enabled for
; 'optnone' functions, just as it is for -O0.
; The test cases @foo[WithOptnone] prove that the same DAG combine happens
; with -O0 and with 'optnone' set. To prove this, we use a Windows triple to
; cause fast-isel to bail out (because something about the calling convention
; is not handled in fast-isel). Then we have a repeated fadd that can be
; combined into an fmul. We show that this happens in both the non-optnone
; function and the optnone function.
define float @foo(float %x) #0 {
entry:
%add = fadd fast float %x, %x
%add1 = fadd fast float %add, %x
ret float %add1
}
; CHECK-LABEL: @foo
; CHECK-NOT: add
; CHECK: mul
; CHECK-NEXT: ret
define float @fooWithOptnone(float %x) #1 {
entry:
%add = fadd fast float %x, %x
%add1 = fadd fast float %add, %x
ret float %add1
}
; CHECK-LABEL: @fooWithOptnone
; CHECK-NOT: add
; CHECK: mul
; CHECK-NEXT: ret
; The test case @bar is derived from an instruction selection failure case
; that was solved by r233153. It depends on -mattr=+avx.
; Really all we're trying to prove is that it doesn't crash any more.
@id84 = common global <16 x i32> zeroinitializer, align 64
define void @bar() #1 {
entry:
%id83 = alloca <16 x i8>, align 16
%0 = load <16 x i32>* @id84, align 64
%conv = trunc <16 x i32> %0 to <16 x i8>
store <16 x i8> %conv, <16 x i8>* %id83, align 16
ret void
}
attributes #0 = { "unsafe-fp-math"="true" }
attributes #1 = { noinline optnone "unsafe-fp-math"="true" }
-35
View File
@@ -1,35 +0,0 @@
; RUN: llc < %s -mcpu=corei7 -march=x86-64 -mattr=+sse2 | FileCheck %s
; Verify that floating-point operations inside 'optnone' functions
; are not optimized even if unsafe-fp-math is set.
define float @foo(float %x) #0 {
entry:
%add = fadd fast float %x, %x
%add1 = fadd fast float %add, %x
ret float %add1
}
; CHECK-LABEL: @foo
; CHECK-NOT: add
; CHECK: mul
; CHECK-NOT: add
; CHECK: ret
define float @fooWithOptnone(float %x) #1 {
entry:
%add = fadd fast float %x, %x
%add1 = fadd fast float %add, %x
ret float %add1
}
; CHECK-LABEL: @fooWithOptnone
; CHECK-NOT: mul
; CHECK: add
; CHECK-NOT: mul
; CHECK: add
; CHECK-NOT: mul
; CHECK: ret
attributes #0 = { "unsafe-fp-math"="true" }
attributes #1 = { noinline optnone "unsafe-fp-math"="true" }