Skip to content

Commit

Permalink
Precommit tests for or/add transform. NFC.
Browse files Browse the repository at this point in the history
llvm-svn: 360149
  • Loading branch information
Robert Lougher authored and MrSidims committed May 17, 2019
1 parent e3823e6 commit e7b0e30
Show file tree
Hide file tree
Showing 2 changed files with 130 additions and 0 deletions.
80 changes: 80 additions & 0 deletions llvm/test/Transforms/InstCombine/add.ll
Expand Up @@ -978,3 +978,83 @@ define i32 @add_to_sub2(i32 %A, i32 %M) {
%E = add i32 %D, 1
ret i32 %E
}

; (X | C1) + C2 --> (X | C1) ^ C1 iff (C1 == -C2)
define i32 @test44(i32 %A) {
; CHECK-LABEL: @test44(
; CHECK-NEXT: [[B:%.*]] = or i32 [[A:%.*]], 123
; CHECK-NEXT: [[C:%.*]] = add nsw i32 [[B]], -123
; CHECK-NEXT: ret i32 [[C]]
;
%B = or i32 %A, 123
%C = add i32 %B, -123
ret i32 %C
}

define i32 @test44_extra_use(i32 %A) {
; CHECK-LABEL: @test44_extra_use(
; CHECK-NEXT: [[B:%.*]] = or i32 [[A:%.*]], 123
; CHECK-NEXT: [[C:%.*]] = add nsw i32 [[B]], -123
; CHECK-NEXT: [[D:%.*]] = mul i32 [[B]], [[C]]
; CHECK-NEXT: ret i32 [[D]]
;
%B = or i32 %A, 123
%C = add i32 %B, -123
%D = mul i32 %B, %C
ret i32 %D
}

define i32 @test44_non_matching(i32 %A) {
; CHECK-LABEL: @test44_non_matching(
; CHECK-NEXT: [[B:%.*]] = or i32 [[A:%.*]], 123
; CHECK-NEXT: [[C:%.*]] = add i32 [[B]], -321
; CHECK-NEXT: ret i32 [[C]]
;
%B = or i32 %A, 123
%C = add i32 %B, -321
ret i32 %C
}

define <2 x i32> @test44_vec(<2 x i32> %A) {
; CHECK-LABEL: @test44_vec(
; CHECK-NEXT: [[B:%.*]] = or <2 x i32> [[A:%.*]], <i32 123, i32 123>
; CHECK-NEXT: [[C:%.*]] = add nsw <2 x i32> [[B]], <i32 -123, i32 -123>
; CHECK-NEXT: ret <2 x i32> [[C]]
;
%B = or <2 x i32> %A, <i32 123, i32 123>
%C = add <2 x i32> %B, <i32 -123, i32 -123>
ret <2 x i32> %C
}

define <2 x i32> @test44_vec_non_matching(<2 x i32> %A) {
; CHECK-LABEL: @test44_vec_non_matching(
; CHECK-NEXT: [[B:%.*]] = or <2 x i32> [[A:%.*]], <i32 123, i32 123>
; CHECK-NEXT: [[C:%.*]] = add <2 x i32> [[B]], <i32 -321, i32 -321>
; CHECK-NEXT: ret <2 x i32> [[C]]
;
%B = or <2 x i32> %A, <i32 123, i32 123>
%C = add <2 x i32> %B, <i32 -321, i32 -321>
ret <2 x i32> %C
}

define <2 x i32> @test44_vec_undef(<2 x i32> %A) {
; CHECK-LABEL: @test44_vec_undef(
; CHECK-NEXT: [[B:%.*]] = or <2 x i32> [[A:%.*]], <i32 123, i32 undef>
; CHECK-NEXT: [[C:%.*]] = add <2 x i32> [[B]], <i32 -123, i32 undef>
; CHECK-NEXT: ret <2 x i32> [[C]]
;
%B = or <2 x i32> %A, <i32 123, i32 undef>
%C = add <2 x i32> %B, <i32 -123, i32 undef>
ret <2 x i32> %C
}

define <2 x i32> @test44_vec_non_splat(<2 x i32> %A) {
; CHECK-LABEL: @test44_vec_non_splat(
; CHECK-NEXT: [[B:%.*]] = or <2 x i32> [[A:%.*]], <i32 123, i32 456>
; CHECK-NEXT: [[C:%.*]] = add <2 x i32> [[B]], <i32 -123, i32 -456>
; CHECK-NEXT: ret <2 x i32> [[C]]
;
%B = or <2 x i32> %A, <i32 123, i32 456>
%C = add <2 x i32> %B, <i32 -123, i32 -456>
ret <2 x i32> %C
}
50 changes: 50 additions & 0 deletions llvm/test/Transforms/InstCombine/sub.ll
Expand Up @@ -1267,6 +1267,56 @@ define <2 x i32> @test69(<2 x i32> %x) {
ret <2 x i32> %res
}

; Check (X | Y) - Y --> X & ~Y when Y is a constant
define i32 @test70(i32 %A) {
; CHECK-LABEL: @test70(
; CHECK-NEXT: [[B:%.*]] = or i32 [[A:%.*]], 123
; CHECK-NEXT: [[C:%.*]] = add nsw i32 [[B]], -123
; CHECK-NEXT: ret i32 [[C]]
;
%B = or i32 %A, 123
%C = sub i32 %B, 123
ret i32 %C
}

; Check (X | Y) - Y --> (X | Y) ^ Y doesn't happen where (X | Y) has multiple uses
define i32 @test71(i32 %A, i32 %B) {
; CHECK-LABEL: @test71(
; CHECK-NEXT: [[C:%.*]] = or i32 [[A:%.*]], [[B:%.*]]
; CHECK-NEXT: [[D:%.*]] = sub i32 [[C]], [[B]]
; CHECK-NEXT: [[E:%.*]] = mul i32 [[C]], [[D]]
; CHECK-NEXT: ret i32 [[E]]
;
%C = or i32 %A, %B
%D = sub i32 %C, %B
%E = mul i32 %C, %D
ret i32 %E
}

; Check (X | Y) - Y --> X & ~Y where X and Y are vectors
define <2 x i32> @test72(<2 x i32> %A, <2 x i32> %B) {
; CHECK-LABEL: @test72(
; CHECK-NEXT: [[B_NOT:%.*]] = xor <2 x i32> [[B:%.*]], <i32 -1, i32 -1>
; CHECK-NEXT: [[D:%.*]] = and <2 x i32> [[B_NOT]], [[A:%.*]]
; CHECK-NEXT: ret <2 x i32> [[D]]
;
%C = or <2 x i32> %A, %B
%D = sub <2 x i32> %C, %B
ret <2 x i32> %D
}

; Check reversing sub operands won't trigger (X | Y) - Y --> X & ~Y
define i32 @test73(i32 %A, i32 %B) {
; CHECK-LABEL: @test73(
; CHECK-NEXT: [[C:%.*]] = or i32 [[A:%.*]], [[B:%.*]]
; CHECK-NEXT: [[D:%.*]] = sub i32 [[B]], [[C]]
; CHECK-NEXT: ret i32 [[D]]
;
%C = or i32 %A, %B
%D = sub i32 %B, %C
ret i32 %D
}

define i32 @nsw_inference1(i32 %x, i32 %y) {
; CHECK-LABEL: @nsw_inference1(
; CHECK-NEXT: [[X2:%.*]] = or i32 [[X:%.*]], 1024
Expand Down

0 comments on commit e7b0e30

Please sign in to comment.