llvm/test/Transforms/InstCombine/assoc-cast-assoc.ll
Sanjay Patel a2db716bbb [InstCombine] LogicOpc (zext X), C --> zext (LogicOpc X, C) (PR28476)
The benefits of this change include:
1. Remove DeMorgan-matching code that was added specifically to work-around 
   the missing transform in http://reviews.llvm.org/rL248634.
2. Makes the DeMorgan transform work for vectors too.
3. Fix PR28476: https://llvm.org/bugs/show_bug.cgi?id=28476

Extending this transform to other casts and other associative operators may
be useful too. See https://reviews.llvm.org/D22421 for a prerequisite for
doing that though.

Differential Revision: https://reviews.llvm.org/D22271



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@276221 91177308-0d34-0410-b5e6-96231b3b80d8
2016-07-21 00:24:18 +00:00

78 lines
2.2 KiB
LLVM

; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt < %s -instcombine -S | FileCheck %s
define i5 @XorZextXor(i3 %a) {
; CHECK-LABEL: @XorZextXor(
; CHECK-NEXT: [[CAST:%.*]] = zext i3 %a to i5
; CHECK-NEXT: [[OP2:%.*]] = xor i5 [[CAST]], 15
; CHECK-NEXT: ret i5 [[OP2]]
;
%op1 = xor i3 %a, 3
%cast = zext i3 %op1 to i5
%op2 = xor i5 %cast, 12
ret i5 %op2
}
define <2 x i32> @XorZextXorVec(<2 x i1> %a) {
; CHECK-LABEL: @XorZextXorVec(
; CHECK-NEXT: [[CAST:%.*]] = zext <2 x i1> %a to <2 x i32>
; CHECK-NEXT: [[OP2:%.*]] = xor <2 x i32> [[CAST]], <i32 2, i32 1>
; CHECK-NEXT: ret <2 x i32> [[OP2]]
;
%op1 = xor <2 x i1> %a, <i1 true, i1 false>
%cast = zext <2 x i1> %op1 to <2 x i32>
%op2 = xor <2 x i32> %cast, <i32 3, i32 1>
ret <2 x i32> %op2
}
define i5 @OrZextOr(i3 %a) {
; CHECK-LABEL: @OrZextOr(
; CHECK-NEXT: [[CAST:%.*]] = zext i3 %a to i5
; CHECK-NEXT: [[OP2:%.*]] = or i5 [[CAST]], 11
; CHECK-NEXT: ret i5 [[OP2]]
;
%op1 = or i3 %a, 3
%cast = zext i3 %op1 to i5
%op2 = or i5 %cast, 8
ret i5 %op2
}
define <2 x i32> @OrZextOrVec(<2 x i2> %a) {
; CHECK-LABEL: @OrZextOrVec(
; CHECK-NEXT: [[CAST:%.*]] = zext <2 x i2> %a to <2 x i32>
; CHECK-NEXT: [[OP2:%.*]] = or <2 x i32> [[CAST]], <i32 3, i32 5>
; CHECK-NEXT: ret <2 x i32> [[OP2]]
;
%op1 = or <2 x i2> %a, <i2 2, i2 0>
%cast = zext <2 x i2> %op1 to <2 x i32>
%op2 = or <2 x i32> %cast, <i32 1, i32 5>
ret <2 x i32> %op2
}
; Unlike the rest, this case is handled by SimplifyDemandedBits / ShrinkDemandedConstant.
define i5 @AndZextAnd(i3 %a) {
; CHECK-LABEL: @AndZextAnd(
; CHECK-NEXT: [[TMP1:%.*]] = and i3 %a, 2
; CHECK-NEXT: [[OP2:%.*]] = zext i3 [[TMP1]] to i5
; CHECK-NEXT: ret i5 [[OP2]]
;
%op1 = and i3 %a, 3
%cast = zext i3 %op1 to i5
%op2 = and i5 %cast, 14
ret i5 %op2
}
define <2 x i32> @AndZextAndVec(<2 x i8> %a) {
; CHECK-LABEL: @AndZextAndVec(
; CHECK-NEXT: [[TMP1:%.*]] = and <2 x i8> %a, <i8 5, i8 0>
; CHECK-NEXT: [[OP2:%.*]] = zext <2 x i8> [[TMP1]] to <2 x i32>
; CHECK-NEXT: ret <2 x i32> [[OP2]]
;
%op1 = and <2 x i8> %a, <i8 7, i8 0>
%cast = zext <2 x i8> %op1 to <2 x i32>
%op2 = and <2 x i32> %cast, <i32 261, i32 1>
ret <2 x i32> %op2
}