diff --git a/llvm/test/Transforms/InstSimplify/select-logical.ll b/llvm/test/Transforms/InstSimplify/select-logical.ll index 0d019dfb77304..3cb7901a01854 100644 --- a/llvm/test/Transforms/InstSimplify/select-logical.ll +++ b/llvm/test/Transforms/InstSimplify/select-logical.ll @@ -586,6 +586,8 @@ define i1 @always_false_same_op(i1 %x) { ret i1 %r } +; (X && Y) || Y --> Y + define i1 @or_and_common_op_commute0(i1 %x, i1 %y) { ; CHECK-LABEL: @or_and_common_op_commute0( ; CHECK-NEXT: ret i1 [[Y:%.*]] @@ -647,3 +649,72 @@ define i1 @or_and_not_common_op(i1 %x, i1 %y, i1 %z) { %r = select i1 %a, i1 true, i1 %z ret i1 %r } + +; (X || Y) && Y --> Y + +define i1 @and_or_common_op_commute0(i1 %x, i1 %y) { +; CHECK-LABEL: @and_or_common_op_commute0( +; CHECK-NEXT: [[O:%.*]] = select i1 [[X:%.*]], i1 true, i1 [[Y:%.*]] +; CHECK-NEXT: [[R:%.*]] = select i1 [[O]], i1 [[Y]], i1 false +; CHECK-NEXT: ret i1 [[R]] +; + %o = select i1 %x, i1 true, i1 %y + %r = select i1 %o, i1 %y, i1 false + ret i1 %r +} + +define <2 x i1> @and_or_common_op_commute1(<2 x i1> %x, <2 x i1> %y) { +; CHECK-LABEL: @and_or_common_op_commute1( +; CHECK-NEXT: [[O:%.*]] = select <2 x i1> [[Y:%.*]], <2 x i1> , <2 x i1> [[X:%.*]] +; CHECK-NEXT: [[R:%.*]] = select <2 x i1> [[O]], <2 x i1> [[Y]], <2 x i1> zeroinitializer +; CHECK-NEXT: ret <2 x i1> [[R]] +; + %o = select <2 x i1> %y, <2 x i1> , <2 x i1> %x + %r = select <2 x i1> %o, <2 x i1> %y, <2 x i1> zeroinitializer + ret <2 x i1> %r +} + + +define <2 x i1> @and_or_common_op_commute2(<2 x i1> %x, <2 x i1> %y) { +; CHECK-LABEL: @and_or_common_op_commute2( +; CHECK-NEXT: [[O:%.*]] = select <2 x i1> [[X:%.*]], <2 x i1> , <2 x i1> [[Y:%.*]] +; CHECK-NEXT: [[R:%.*]] = select <2 x i1> [[Y]], <2 x i1> [[O]], <2 x i1> +; CHECK-NEXT: ret <2 x i1> [[R]] +; + %o = select <2 x i1> %x, <2 x i1> , <2 x i1> %y + %r = select <2 x i1> %y, <2 x i1> %o, <2 x i1> + ret <2 x i1> %r +} + +define <2 x i1> @and_or_common_op_commute3(<2 x i1> %x, <2 x i1> %y) { +; CHECK-LABEL: @and_or_common_op_commute3( +; CHECK-NEXT: [[O:%.*]] = select <2 x i1> [[Y:%.*]], <2 x i1> , <2 x i1> [[X:%.*]] +; CHECK-NEXT: [[R:%.*]] = select <2 x i1> [[Y]], <2 x i1> [[O]], <2 x i1> zeroinitializer +; CHECK-NEXT: ret <2 x i1> [[R]] +; + %o = select <2 x i1> %y, <2 x i1> , <2 x i1> %x + %r = select <2 x i1> %y, <2 x i1> %o, <2 x i1> zeroinitializer + ret <2 x i1> %r +} + +define <2 x i1> @and_or_common_op_commute3_poison(<2 x i1> %x, <2 x i1> %y) { +; CHECK-LABEL: @and_or_common_op_commute3_poison( +; CHECK-NEXT: [[O:%.*]] = select <2 x i1> [[Y:%.*]], <2 x i1> , <2 x i1> [[X:%.*]] +; CHECK-NEXT: [[R:%.*]] = select <2 x i1> [[Y]], <2 x i1> [[O]], <2 x i1> zeroinitializer +; CHECK-NEXT: ret <2 x i1> [[R]] +; + %o = select <2 x i1> %y, <2 x i1> , <2 x i1> %x + %r = select <2 x i1> %y, <2 x i1> %o, <2 x i1> zeroinitializer + ret <2 x i1> %r +} + +define i1 @and_or_not_common_op(i1 %x, i1 %y, i1 %z) { +; CHECK-LABEL: @and_or_not_common_op( +; CHECK-NEXT: [[O:%.*]] = select i1 [[X:%.*]], i1 true, i1 [[Y:%.*]] +; CHECK-NEXT: [[R:%.*]] = select i1 [[Z:%.*]], i1 [[O]], i1 false +; CHECK-NEXT: ret i1 [[R]] +; + %o = select i1 %x, i1 true, i1 %y + %r = select i1 %z, i1 %o, i1 false + ret i1 %r +}