mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-07-22 23:24:59 +00:00
fix a fairly serious oversight with switch formation from
or'd conditions. Previously we'd compile something like this: int crud (unsigned char c) { return c == 62 || c == 34 || c == 92; } into: switch i8 %c, label %lor.rhs [ i8 62, label %lor.end i8 34, label %lor.end ] lor.rhs: ; preds = %entry %cmp8 = icmp eq i8 %c, 92 br label %lor.end lor.end: ; preds = %entry, %entry, %lor.rhs %0 = phi i1 [ true, %entry ], [ %cmp8, %lor.rhs ], [ true, %entry ] %lor.ext = zext i1 %0 to i32 ret i32 %lor.ext which failed to merge the compare-with-92 into the switch. With this patch we simplify this all the way to: switch i8 %c, label %lor.rhs [ i8 62, label %lor.end i8 34, label %lor.end i8 92, label %lor.end ] lor.rhs: ; preds = %entry br label %lor.end lor.end: ; preds = %entry, %entry, %entry, %lor.rhs %0 = phi i1 [ true, %entry ], [ false, %lor.rhs ], [ true, %entry ], [ true, %entry ] %lor.ext = zext i1 %0 to i32 ret i32 %lor.ext which is much better for codegen's switch lowering stuff. This kicks in 33 times on 176.gcc (for example) cutting 103 instructions off the generated code. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@121671 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
; RUN: opt < %s -simplifycfg -S | not grep br
|
||||
; RUN: opt < %s -simplifycfg -S | FileCheck %s
|
||||
|
||||
declare void @foo1()
|
||||
|
||||
@@ -15,6 +15,11 @@ T: ; preds = %0
|
||||
F: ; preds = %0
|
||||
call void @foo2( )
|
||||
ret void
|
||||
; CHECK: @test1
|
||||
; CHECK: switch i32 %V, label %F [
|
||||
; CHECK: i32 17, label %T
|
||||
; CHECK: i32 4, label %T
|
||||
; CHECK: ]
|
||||
}
|
||||
|
||||
define void @test2(i32 %V) {
|
||||
@@ -28,6 +33,11 @@ T: ; preds = %0
|
||||
F: ; preds = %0
|
||||
call void @foo2( )
|
||||
ret void
|
||||
; CHECK: @test2
|
||||
; CHECK: switch i32 %V, label %T [
|
||||
; CHECK: i32 17, label %F
|
||||
; CHECK: i32 4, label %F
|
||||
; CHECK: ]
|
||||
}
|
||||
|
||||
define void @test3(i32 %V) {
|
||||
@@ -42,6 +52,39 @@ T: ; preds = %N, %0
|
||||
F: ; preds = %N
|
||||
call void @foo2( )
|
||||
ret void
|
||||
|
||||
; CHECK: @test3
|
||||
; CHECK: switch i32 %V, label %F [
|
||||
; CHECK: i32 4, label %T
|
||||
; CHECK: i32 17, label %T
|
||||
; CHECK: ]
|
||||
}
|
||||
|
||||
|
||||
|
||||
define i32 @test4(i8 zeroext %c) nounwind ssp noredzone {
|
||||
entry:
|
||||
%cmp = icmp eq i8 %c, 62
|
||||
br i1 %cmp, label %lor.end, label %lor.lhs.false
|
||||
|
||||
lor.lhs.false: ; preds = %entry
|
||||
%cmp4 = icmp eq i8 %c, 34
|
||||
br i1 %cmp4, label %lor.end, label %lor.rhs
|
||||
|
||||
lor.rhs: ; preds = %lor.lhs.false
|
||||
%cmp8 = icmp eq i8 %c, 92
|
||||
br label %lor.end
|
||||
|
||||
lor.end: ; preds = %lor.rhs, %lor.lhs.false, %entry
|
||||
%0 = phi i1 [ true, %lor.lhs.false ], [ true, %entry ], [ %cmp8, %lor.rhs ]
|
||||
%lor.ext = zext i1 %0 to i32
|
||||
ret i32 %lor.ext
|
||||
|
||||
; CHECK: @test4
|
||||
; CHECK: switch i8 %c, label %lor.rhs [
|
||||
; CHECK: i8 62, label %lor.end
|
||||
; CHECK: i8 34, label %lor.end
|
||||
; CHECK: i8 92, label %lor.end
|
||||
; CHECK: ]
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user