2011-01-03 07:04:14 +08:00
|
|
|
; RUN: opt < %s -S -early-cse | FileCheck %s
|
|
|
|
|
|
|
|
|
|
|
|
; CHECK: @test1
|
|
|
|
define void @test1(i8 %V, i32 *%P) {
|
|
|
|
%A = bitcast i64 42 to double ;; dead
|
|
|
|
%B = add i32 4, 19 ;; constant folds
|
|
|
|
store i32 %B, i32* %P
|
|
|
|
; CHECK-NEXT: store i32 23, i32* %P
|
|
|
|
|
|
|
|
%C = zext i8 %V to i32
|
|
|
|
%D = zext i8 %V to i32 ;; CSE
|
|
|
|
volatile store i32 %C, i32* %P
|
|
|
|
volatile store i32 %D, i32* %P
|
|
|
|
; CHECK-NEXT: %C = zext i8 %V to i32
|
|
|
|
; CHECK-NEXT: volatile store i32 %C
|
|
|
|
; CHECK-NEXT: volatile store i32 %C
|
2011-01-03 07:19:45 +08:00
|
|
|
|
|
|
|
%E = add i32 %C, %C
|
|
|
|
%F = add i32 %C, %C
|
|
|
|
volatile store i32 %E, i32* %P
|
|
|
|
volatile store i32 %F, i32* %P
|
|
|
|
; CHECK-NEXT: %E = add i32 %C, %C
|
|
|
|
; CHECK-NEXT: volatile store i32 %E
|
|
|
|
; CHECK-NEXT: volatile store i32 %E
|
|
|
|
|
|
|
|
%G = add nuw i32 %C, %C ;; not a CSE with E
|
|
|
|
volatile store i32 %G, i32* %P
|
|
|
|
; CHECK-NEXT: %G = add nuw i32 %C, %C
|
|
|
|
; CHECK-NEXT: volatile store i32 %G
|
2011-01-03 07:04:14 +08:00
|
|
|
ret void
|
|
|
|
}
|
2011-01-03 11:18:43 +08:00
|
|
|
|
|
|
|
|
|
|
|
;; Simple load value numbering.
|
|
|
|
; CHECK: @test2
|
|
|
|
define i32 @test2(i32 *%P) {
|
|
|
|
%V1 = load i32* %P
|
|
|
|
%V2 = load i32* %P
|
|
|
|
%Diff = sub i32 %V1, %V2
|
|
|
|
ret i32 %Diff
|
|
|
|
; CHECK: ret i32 0
|
|
|
|
}
|
|
|
|
|
|
|
|
;; Cross block load value numbering.
|
|
|
|
; CHECK: @test3
|
|
|
|
define i32 @test3(i32 *%P, i1 %Cond) {
|
|
|
|
%V1 = load i32* %P
|
|
|
|
br i1 %Cond, label %T, label %F
|
|
|
|
T:
|
|
|
|
store i32 4, i32* %P
|
|
|
|
ret i32 42
|
|
|
|
F:
|
|
|
|
%V2 = load i32* %P
|
|
|
|
%Diff = sub i32 %V1, %V2
|
|
|
|
ret i32 %Diff
|
|
|
|
; CHECK: F:
|
|
|
|
; CHECK: ret i32 0
|
|
|
|
}
|
|
|
|
|
|
|
|
;; Cross block load value numbering stops when stores happen.
|
|
|
|
; CHECK: @test4
|
|
|
|
define i32 @test4(i32 *%P, i1 %Cond) {
|
|
|
|
%V1 = load i32* %P
|
|
|
|
br i1 %Cond, label %T, label %F
|
|
|
|
T:
|
|
|
|
ret i32 42
|
|
|
|
F:
|
|
|
|
; Clobbers V1
|
|
|
|
store i32 42, i32* %P
|
|
|
|
|
|
|
|
%V2 = load i32* %P
|
|
|
|
%Diff = sub i32 %V1, %V2
|
|
|
|
ret i32 %Diff
|
|
|
|
; CHECK: F:
|
|
|
|
; CHECK: ret i32 %Diff
|
|
|
|
}
|