diff --git a/llvm/test/Transforms/InstCombine/icmp-logical.ll b/llvm/test/Transforms/InstCombine/icmp-logical.ll --- a/llvm/test/Transforms/InstCombine/icmp-logical.ll +++ b/llvm/test/Transforms/InstCombine/icmp-logical.ll @@ -1768,3 +1768,672 @@ %t5 = select i1 %t4, i1 true, i1 %t2 ret i1 %t5 } + +; Issue #54856 + +; ((X u< 0x8000000) & ((X & 0x60000000) != 0x60000000)) -> X u< 0x60000000 +define i1 @masked_icmps_mask_allzeros_bmask_notmixed_and_notallones_1(i32 %x) { +; CHECK-LABEL: @masked_icmps_mask_allzeros_bmask_notmixed_and_notallones_1( +; CHECK-NEXT: [[T1:%.*]] = icmp sgt i32 [[X:%.*]], -1 +; CHECK-NEXT: [[T2:%.*]] = and i32 [[X]], 1610612736 +; CHECK-NEXT: [[T3:%.*]] = icmp ne i32 [[T2]], 1610612736 +; CHECK-NEXT: [[T4:%.*]] = and i1 [[T1]], [[T3]] +; CHECK-NEXT: ret i1 [[T4]] +; + %t1 = icmp ult i32 %x, 2147483648 + %t2 = and i32 %x, 1610612736 + %t3 = icmp ne i32 %t2, 1610612736 + %t4 = and i1 %t1, %t3 + ret i1 %t4 +} + +define i1 @masked_icmps_mask_allzeros_bmask_notmixed_and_notallones_swapped_1(i32 %x) { +; CHECK-LABEL: @masked_icmps_mask_allzeros_bmask_notmixed_and_notallones_swapped_1( +; CHECK-NEXT: [[T1:%.*]] = icmp sgt i32 [[X:%.*]], -1 +; CHECK-NEXT: [[T2:%.*]] = and i32 [[X]], 1610612736 +; CHECK-NEXT: [[T3:%.*]] = icmp ne i32 [[T2]], 1610612736 +; CHECK-NEXT: [[T4:%.*]] = and i1 [[T3]], [[T1]] +; CHECK-NEXT: ret i1 [[T4]] +; + %t1 = icmp ult i32 %x, 2147483648 + %t2 = and i32 %x, 1610612736 + %t3 = icmp ne i32 %t2, 1610612736 + %t4 = and i1 %t3, %t1 + ret i1 %t4 +} + +; ((X u< 0x8000000) & ((X & 0x7FFFFFFF) != 0x7FFFFFFF)) -> X u< 0x7FFFFFFF +define i1 @masked_icmps_mask_allzeros_bmask_notmixed_and_notallones_2(i32 %x) { +; CHECK-LABEL: @masked_icmps_mask_allzeros_bmask_notmixed_and_notallones_2( +; CHECK-NEXT: [[T1:%.*]] = icmp sgt i32 [[X:%.*]], -1 +; CHECK-NEXT: [[T2:%.*]] = and i32 [[X]], 2147483647 +; CHECK-NEXT: [[T3:%.*]] = icmp ne i32 [[T2]], 2147483647 +; CHECK-NEXT: [[T4:%.*]] = and i1 [[T1]], [[T3]] +; CHECK-NEXT: ret i1 [[T4]] +; + %t1 = icmp ult i32 %x, 2147483648 + %t2 = and i32 %x, 2147483647 + %t3 = icmp ne i32 %t2, 2147483647 + %t4 = and i1 %t1, %t3 + ret i1 %t4 +} + +define i1 @masked_icmps_mask_allzeros_bmask_notmixed_and_notallones_swapped_2(i32 %x) { +; CHECK-LABEL: @masked_icmps_mask_allzeros_bmask_notmixed_and_notallones_swapped_2( +; CHECK-NEXT: [[T1:%.*]] = icmp sgt i32 [[X:%.*]], -1 +; CHECK-NEXT: [[T2:%.*]] = and i32 [[X]], 2147483647 +; CHECK-NEXT: [[T3:%.*]] = icmp ne i32 [[T2]], 2147483647 +; CHECK-NEXT: [[T4:%.*]] = and i1 [[T3]], [[T1]] +; CHECK-NEXT: ret i1 [[T4]] +; + %t1 = icmp ult i32 %x, 2147483648 + %t2 = and i32 %x, 2147483647 + %t3 = icmp ne i32 %t2, 2147483647 + %t4 = and i1 %t3, %t1 + ret i1 %t4 +} + +; ((X u< 0x4000000) & ((X & 0x30000000) != 0x30000000)) -> X u< 0x30000000 +define i1 @masked_icmps_mask_allzeros_bmask_notmixed_and_notallones_3(i32 %x) { +; CHECK-LABEL: @masked_icmps_mask_allzeros_bmask_notmixed_and_notallones_3( +; CHECK-NEXT: [[T1:%.*]] = icmp ult i32 [[X:%.*]], 1073741824 +; CHECK-NEXT: [[T2:%.*]] = and i32 [[X]], 805306368 +; CHECK-NEXT: [[T3:%.*]] = icmp ne i32 [[T2]], 805306368 +; CHECK-NEXT: [[T4:%.*]] = and i1 [[T1]], [[T3]] +; CHECK-NEXT: ret i1 [[T4]] +; + %t1 = icmp ult i32 %x, 1073741824 + %t2 = and i32 %x, 805306368 + %t3 = icmp ne i32 %t2, 805306368 + %t4 = and i1 %t1, %t3 + ret i1 %t4 +} + +define i1 @masked_icmps_mask_allzeros_bmask_notmixed_and_notallones_swapped_3(i32 %x) { +; CHECK-LABEL: @masked_icmps_mask_allzeros_bmask_notmixed_and_notallones_swapped_3( +; CHECK-NEXT: [[T1:%.*]] = icmp ult i32 [[X:%.*]], 1073741824 +; CHECK-NEXT: [[T2:%.*]] = and i32 [[X]], 805306368 +; CHECK-NEXT: [[T3:%.*]] = icmp ne i32 [[T2]], 805306368 +; CHECK-NEXT: [[T4:%.*]] = and i1 [[T3]], [[T1]] +; CHECK-NEXT: ret i1 [[T4]] +; + %t1 = icmp ult i32 %x, 1073741824 + %t2 = and i32 %x, 805306368 + %t3 = icmp ne i32 %t2, 805306368 + %t4 = and i1 %t3, %t1 + ret i1 %t4 +} + +; ((X u< 0x40000000) & ((X & 0x3FFFFFFF) != 0x3FFFFFFF)) -> X u< 0x3FFFFFFF +define i1 @masked_icmps_mask_allzeros_bmask_notmixed_and_notallones_4(i32 %x) { +; CHECK-LABEL: @masked_icmps_mask_allzeros_bmask_notmixed_and_notallones_4( +; CHECK-NEXT: [[T1:%.*]] = icmp ult i32 [[X:%.*]], 1073741824 +; CHECK-NEXT: [[T2:%.*]] = and i32 [[X]], 1073741823 +; CHECK-NEXT: [[T3:%.*]] = icmp ne i32 [[T2]], 1073741823 +; CHECK-NEXT: [[T4:%.*]] = and i1 [[T1]], [[T3]] +; CHECK-NEXT: ret i1 [[T4]] +; + %t1 = icmp ult i32 %x, 1073741824 + %t2 = and i32 %x, 1073741823 + %t3 = icmp ne i32 %t2, 1073741823 + %t4 = and i1 %t1, %t3 + ret i1 %t4 +} + +define i1 @masked_icmps_mask_allzeros_bmask_notmixed_and_notallones_swapped_4(i32 %x) { +; CHECK-LABEL: @masked_icmps_mask_allzeros_bmask_notmixed_and_notallones_swapped_4( +; CHECK-NEXT: [[T1:%.*]] = icmp ult i32 [[X:%.*]], 1073741824 +; CHECK-NEXT: [[T2:%.*]] = and i32 [[X]], 1073741823 +; CHECK-NEXT: [[T3:%.*]] = icmp ne i32 [[T2]], 1073741823 +; CHECK-NEXT: [[T4:%.*]] = and i1 [[T3]], [[T1]] +; CHECK-NEXT: ret i1 [[T4]] +; + %t1 = icmp ult i32 %x, 1073741824 + %t2 = and i32 %x, 1073741823 + %t3 = icmp ne i32 %t2, 1073741823 + %t4 = and i1 %t3, %t1 + ret i1 %t4 +} + +; ((X u< 8) & ((X & 7) != 7)) -> X u< 7 +define i1 @masked_icmps_mask_allzeros_bmask_notmixed_and_notallones_5(i32 %x) { +; CHECK-LABEL: @masked_icmps_mask_allzeros_bmask_notmixed_and_notallones_5( +; CHECK-NEXT: [[T1:%.*]] = icmp ult i32 [[X:%.*]], 8 +; CHECK-NEXT: [[T2:%.*]] = and i32 [[X]], 7 +; CHECK-NEXT: [[T3:%.*]] = icmp ne i32 [[T2]], 7 +; CHECK-NEXT: [[T4:%.*]] = and i1 [[T1]], [[T3]] +; CHECK-NEXT: ret i1 [[T4]] +; + %t1 = icmp ult i32 %x, 8 + %t2 = and i32 %x, 7 + %t3 = icmp ne i32 %t2, 7 + %t4 = and i1 %t1, %t3 + ret i1 %t4 +} + +define i1 @masked_icmps_mask_allzeros_bmask_notmixed_and_notallones_swapped_5(i32 %x) { +; CHECK-LABEL: @masked_icmps_mask_allzeros_bmask_notmixed_and_notallones_swapped_5( +; CHECK-NEXT: [[T1:%.*]] = icmp ult i32 [[X:%.*]], 8 +; CHECK-NEXT: [[T2:%.*]] = and i32 [[X]], 7 +; CHECK-NEXT: [[T3:%.*]] = icmp ne i32 [[T2]], 7 +; CHECK-NEXT: [[T4:%.*]] = and i1 [[T3]], [[T1]] +; CHECK-NEXT: ret i1 [[T4]] +; + %t1 = icmp ult i32 %x, 8 + %t2 = and i32 %x, 7 + %t3 = icmp ne i32 %t2, 7 + %t4 = and i1 %t3, %t1 + ret i1 %t4 +} + +; ((X u< 8) & ((X & 6) != 6)) -> X u< 6 +define i1 @masked_icmps_mask_allzeros_bmask_notmixed_and_notallones_6(i32 %x) { +; CHECK-LABEL: @masked_icmps_mask_allzeros_bmask_notmixed_and_notallones_6( +; CHECK-NEXT: [[T1:%.*]] = icmp ult i32 [[X:%.*]], 8 +; CHECK-NEXT: [[T2:%.*]] = and i32 [[X]], 6 +; CHECK-NEXT: [[T3:%.*]] = icmp ne i32 [[T2]], 6 +; CHECK-NEXT: [[T4:%.*]] = and i1 [[T1]], [[T3]] +; CHECK-NEXT: ret i1 [[T4]] +; + %t1 = icmp ult i32 %x, 8 + %t2 = and i32 %x, 6 + %t3 = icmp ne i32 %t2, 6 + %t4 = and i1 %t1, %t3 + ret i1 %t4 +} + +define i1 @masked_icmps_mask_allzeros_bmask_notmixed_and_notallones_swapped_6(i32 %x) { +; CHECK-LABEL: @masked_icmps_mask_allzeros_bmask_notmixed_and_notallones_swapped_6( +; CHECK-NEXT: [[T1:%.*]] = icmp ult i32 [[X:%.*]], 8 +; CHECK-NEXT: [[T2:%.*]] = and i32 [[X]], 6 +; CHECK-NEXT: [[T3:%.*]] = icmp ne i32 [[T2]], 6 +; CHECK-NEXT: [[T4:%.*]] = and i1 [[T3]], [[T1]] +; CHECK-NEXT: ret i1 [[T4]] +; + %t1 = icmp ult i32 %x, 8 + %t2 = and i32 %x, 6 + %t3 = icmp ne i32 %t2, 6 + %t4 = and i1 %t3, %t1 + ret i1 %t4 +} + +; ((X u< 8) & ((X & 5) != 5)) -> no change +define i1 @masked_icmps_mask_allzeros_bmask_notmixed_and_notallones_7(i32 %x) { +; CHECK-LABEL: @masked_icmps_mask_allzeros_bmask_notmixed_and_notallones_7( +; CHECK-NEXT: [[T1:%.*]] = icmp ult i32 [[X:%.*]], 8 +; CHECK-NEXT: [[T2:%.*]] = and i32 [[X]], 5 +; CHECK-NEXT: [[T3:%.*]] = icmp ne i32 [[T2]], 5 +; CHECK-NEXT: [[T4:%.*]] = and i1 [[T1]], [[T3]] +; CHECK-NEXT: ret i1 [[T4]] +; + %t1 = icmp ult i32 %x, 8 + %t2 = and i32 %x, 5 + %t3 = icmp ne i32 %t2, 5 + %t4 = and i1 %t1, %t3 + ret i1 %t4 +} + +define i1 @masked_icmps_mask_allzeros_bmask_notmixed_and_notallones_swapped_7(i32 %x) { +; CHECK-LABEL: @masked_icmps_mask_allzeros_bmask_notmixed_and_notallones_swapped_7( +; CHECK-NEXT: [[T1:%.*]] = icmp ult i32 [[X:%.*]], 8 +; CHECK-NEXT: [[T2:%.*]] = and i32 [[X]], 5 +; CHECK-NEXT: [[T3:%.*]] = icmp ne i32 [[T2]], 5 +; CHECK-NEXT: [[T4:%.*]] = and i1 [[T3]], [[T1]] +; CHECK-NEXT: ret i1 [[T4]] +; + %t1 = icmp ult i32 %x, 8 + %t2 = and i32 %x, 5 + %t3 = icmp ne i32 %t2, 5 + %t4 = and i1 %t3, %t1 + ret i1 %t4 +} + +; ((X u< 8) & ((X & 3) != 3)) -> no change +define i1 @masked_icmps_mask_allzeros_bmask_notmixed_and_notallones_8(i32 %x) { +; CHECK-LABEL: @masked_icmps_mask_allzeros_bmask_notmixed_and_notallones_8( +; CHECK-NEXT: [[T1:%.*]] = icmp ult i32 [[X:%.*]], 8 +; CHECK-NEXT: [[T2:%.*]] = and i32 [[X]], 3 +; CHECK-NEXT: [[T3:%.*]] = icmp ne i32 [[T2]], 3 +; CHECK-NEXT: [[T4:%.*]] = and i1 [[T1]], [[T3]] +; CHECK-NEXT: ret i1 [[T4]] +; + %t1 = icmp ult i32 %x, 8 + %t2 = and i32 %x, 3 + %t3 = icmp ne i32 %t2, 3 + %t4 = and i1 %t1, %t3 + ret i1 %t4 +} + +define i1 @masked_icmps_mask_allzeros_bmask_notmixed_and_notallones_swapped_8(i32 %x) { +; CHECK-LABEL: @masked_icmps_mask_allzeros_bmask_notmixed_and_notallones_swapped_8( +; CHECK-NEXT: [[T1:%.*]] = icmp ult i32 [[X:%.*]], 8 +; CHECK-NEXT: [[T2:%.*]] = and i32 [[X]], 3 +; CHECK-NEXT: [[T3:%.*]] = icmp ne i32 [[T2]], 3 +; CHECK-NEXT: [[T4:%.*]] = and i1 [[T3]], [[T1]] +; CHECK-NEXT: ret i1 [[T4]] +; + %t1 = icmp ult i32 %x, 8 + %t2 = and i32 %x, 3 + %t3 = icmp ne i32 %t2, 3 + %t4 = and i1 %t3, %t1 + ret i1 %t4 +} + +; ((X u< 0x100) & ((X & 0x0EF) != 0x0EF)) -> no change +define i1 @masked_icmps_mask_allzeros_bmask_notmixed_and_notallones_9(i32 %x) { +; CHECK-LABEL: @masked_icmps_mask_allzeros_bmask_notmixed_and_notallones_9( +; CHECK-NEXT: [[T1:%.*]] = icmp ult i32 [[X:%.*]], 256 +; CHECK-NEXT: [[T2:%.*]] = and i32 [[X]], 239 +; CHECK-NEXT: [[T3:%.*]] = icmp ne i32 [[T2]], 239 +; CHECK-NEXT: [[T4:%.*]] = and i1 [[T1]], [[T3]] +; CHECK-NEXT: ret i1 [[T4]] +; + %t1 = icmp ult i32 %x, 256 + %t2 = and i32 %x, 239 + %t3 = icmp ne i32 %t2, 239 + %t4 = and i1 %t1, %t3 + ret i1 %t4 +} + +define i1 @masked_icmps_mask_allzeros_bmask_notmixed_and_notallones_swapped_9(i32 %x) { +; CHECK-LABEL: @masked_icmps_mask_allzeros_bmask_notmixed_and_notallones_swapped_9( +; CHECK-NEXT: [[T1:%.*]] = icmp ult i32 [[X:%.*]], 256 +; CHECK-NEXT: [[T2:%.*]] = and i32 [[X]], 239 +; CHECK-NEXT: [[T3:%.*]] = icmp ne i32 [[T2]], 239 +; CHECK-NEXT: [[T4:%.*]] = and i1 [[T3]], [[T1]] +; CHECK-NEXT: ret i1 [[T4]] +; + %t1 = icmp ult i32 %x, 256 + %t2 = and i32 %x, 239 + %t3 = icmp ne i32 %t2, 239 + %t4 = and i1 %t3, %t1 + ret i1 %t4 +} + +; ((X u< 0x08) & ((X & 0x70) != 0x70)) -> no change +define i1 @masked_icmps_mask_allzeros_bmask_notmixed_and_notallones_10(i32 %x) { +; CHECK-LABEL: @masked_icmps_mask_allzeros_bmask_notmixed_and_notallones_10( +; CHECK-NEXT: [[T1:%.*]] = icmp ult i32 [[X:%.*]], 8 +; CHECK-NEXT: [[T2:%.*]] = and i32 [[X]], 112 +; CHECK-NEXT: [[T3:%.*]] = icmp ne i32 [[T2]], 112 +; CHECK-NEXT: [[T4:%.*]] = and i1 [[T1]], [[T3]] +; CHECK-NEXT: ret i1 [[T4]] +; + %t1 = icmp ult i32 %x, 8 + %t2 = and i32 %x, 112 + %t3 = icmp ne i32 %t2, 112 + %t4 = and i1 %t1, %t3 + ret i1 %t4 +} + +define i1 @masked_icmps_mask_allzeros_bmask_notmixed_and_notallones_swapped_10(i32 %x) { +; CHECK-LABEL: @masked_icmps_mask_allzeros_bmask_notmixed_and_notallones_swapped_10( +; CHECK-NEXT: [[T1:%.*]] = icmp ult i32 [[X:%.*]], 8 +; CHECK-NEXT: [[T2:%.*]] = and i32 [[X]], 112 +; CHECK-NEXT: [[T3:%.*]] = icmp ne i32 [[T2]], 112 +; CHECK-NEXT: [[T4:%.*]] = and i1 [[T3]], [[T1]] +; CHECK-NEXT: ret i1 [[T4]] +; + %t1 = icmp ult i32 %x, 8 + %t2 = and i32 %x, 112 + %t3 = icmp ne i32 %t2, 112 + %t4 = and i1 %t3, %t1 + ret i1 %t4 +} + +; ((X u< 0x08) & ((X & 0x38) != 0x38))) -> no change +define i1 @masked_icmps_mask_allzeros_bmask_notmixed_and_notallones_11(i32 %x) { +; CHECK-LABEL: @masked_icmps_mask_allzeros_bmask_notmixed_and_notallones_11( +; CHECK-NEXT: [[T1:%.*]] = icmp ult i32 [[X:%.*]], 8 +; CHECK-NEXT: [[T2:%.*]] = and i32 [[X]], 56 +; CHECK-NEXT: [[T3:%.*]] = icmp ne i32 [[T2]], 56 +; CHECK-NEXT: [[T4:%.*]] = and i1 [[T1]], [[T3]] +; CHECK-NEXT: ret i1 [[T4]] +; + %t1 = icmp ult i32 %x, 8 + %t2 = and i32 %x, 56 + %t3 = icmp ne i32 %t2, 56 + %t4 = and i1 %t1, %t3 + ret i1 %t4 +} + +define i1 @masked_icmps_mask_allzeros_bmask_notmixed_and_notallones_swapped_11(i32 %x) { +; CHECK-LABEL: @masked_icmps_mask_allzeros_bmask_notmixed_and_notallones_swapped_11( +; CHECK-NEXT: [[T1:%.*]] = icmp ult i32 [[X:%.*]], 8 +; CHECK-NEXT: [[T2:%.*]] = and i32 [[X]], 56 +; CHECK-NEXT: [[T3:%.*]] = icmp ne i32 [[T2]], 56 +; CHECK-NEXT: [[T4:%.*]] = and i1 [[T3]], [[T1]] +; CHECK-NEXT: ret i1 [[T4]] +; + %t1 = icmp ult i32 %x, 8 + %t2 = and i32 %x, 56 + %t3 = icmp ne i32 %t2, 56 + %t4 = and i1 %t3, %t1 + ret i1 %t4 +} + +; ((X u< 0x08) & ((X & 0x18) != 0x18)) -> no change +define i1 @masked_icmps_mask_allzeros_bmask_notmixed_and_notallones_12(i32 %x) { +; CHECK-LABEL: @masked_icmps_mask_allzeros_bmask_notmixed_and_notallones_12( +; CHECK-NEXT: [[T1:%.*]] = icmp ult i32 [[X:%.*]], 8 +; CHECK-NEXT: [[T2:%.*]] = and i32 [[X]], 24 +; CHECK-NEXT: [[T3:%.*]] = icmp ne i32 [[T2]], 24 +; CHECK-NEXT: [[T4:%.*]] = and i1 [[T1]], [[T3]] +; CHECK-NEXT: ret i1 [[T4]] +; + %t1 = icmp ult i32 %x, 8 + %t2 = and i32 %x, 24 + %t3 = icmp ne i32 %t2, 24 + %t4 = and i1 %t1, %t3 + ret i1 %t4 +} + +define i1 @masked_icmps_mask_allzeros_bmask_notmixed_and_notallones_swapped_12(i32 %x) { +; CHECK-LABEL: @masked_icmps_mask_allzeros_bmask_notmixed_and_notallones_swapped_12( +; CHECK-NEXT: [[T1:%.*]] = icmp ult i32 [[X:%.*]], 8 +; CHECK-NEXT: [[T2:%.*]] = and i32 [[X]], 24 +; CHECK-NEXT: [[T3:%.*]] = icmp ne i32 [[T2]], 24 +; CHECK-NEXT: [[T4:%.*]] = and i1 [[T3]], [[T1]] +; CHECK-NEXT: ret i1 [[T4]] +; + %t1 = icmp ult i32 %x, 8 + %t2 = and i32 %x, 24 + %t3 = icmp ne i32 %t2, 24 + %t4 = and i1 %t3, %t1 + ret i1 %t4 +} + +; ((X u< 0x8) & ((X & 0xC) != 0xC)) -> no change +define i1 @masked_icmps_mask_allzeros_bmask_notmixed_and_notallones_13(i32 %x) { +; CHECK-LABEL: @masked_icmps_mask_allzeros_bmask_notmixed_and_notallones_13( +; CHECK-NEXT: [[T1:%.*]] = icmp ult i32 [[X:%.*]], 8 +; CHECK-NEXT: [[T2:%.*]] = and i32 [[X]], 12 +; CHECK-NEXT: [[T3:%.*]] = icmp ne i32 [[T2]], 12 +; CHECK-NEXT: [[T4:%.*]] = and i1 [[T1]], [[T3]] +; CHECK-NEXT: ret i1 [[T4]] +; + %t1 = icmp ult i32 %x, 8 + %t2 = and i32 %x, 12 + %t3 = icmp ne i32 %t2, 12 + %t4 = and i1 %t1, %t3 + ret i1 %t4 +} + +define i1 @masked_icmps_mask_allzeros_bmask_notmixed_and_notallones_swapped_13(i32 %x) { +; CHECK-LABEL: @masked_icmps_mask_allzeros_bmask_notmixed_and_notallones_swapped_13( +; CHECK-NEXT: [[T1:%.*]] = icmp ult i32 [[X:%.*]], 8 +; CHECK-NEXT: [[T2:%.*]] = and i32 [[X]], 12 +; CHECK-NEXT: [[T3:%.*]] = icmp ne i32 [[T2]], 12 +; CHECK-NEXT: [[T4:%.*]] = and i1 [[T3]], [[T1]] +; CHECK-NEXT: ret i1 [[T4]] +; + %t1 = icmp ult i32 %x, 8 + %t2 = and i32 %x, 12 + %t3 = icmp ne i32 %t2, 12 + %t4 = and i1 %t3, %t1 + ret i1 %t4 +} + +; Vector of 1 reduction +define <1 x i1> @masked_icmps_mask_allzeros_bmask_notmixed_and_notallones_14(<1 x i32> %x) { +; CHECK-LABEL: @masked_icmps_mask_allzeros_bmask_notmixed_and_notallones_14( +; CHECK-NEXT: [[T1:%.*]] = icmp sgt <1 x i32> [[X:%.*]], +; CHECK-NEXT: [[T2:%.*]] = and <1 x i32> [[X]], +; CHECK-NEXT: [[T3:%.*]] = icmp ne <1 x i32> [[T2]], +; CHECK-NEXT: [[T4:%.*]] = and <1 x i1> [[T1]], [[T3]] +; CHECK-NEXT: ret <1 x i1> [[T4]] +; + %t1 = icmp ult <1 x i32> %x, + %t2 = and <1 x i32> %x, + %t3 = icmp ne <1 x i32> %t2, + %t4 = and <1 x i1> %t1, %t3 + ret <1 x i1> %t4 +} + +define <1 x i1> @masked_icmps_mask_allzeros_bmask_notmixed_and_notallones_swapped_14(<1 x i32> %x) { +; CHECK-LABEL: @masked_icmps_mask_allzeros_bmask_notmixed_and_notallones_swapped_14( +; CHECK-NEXT: [[T1:%.*]] = icmp sgt <1 x i32> [[X:%.*]], +; CHECK-NEXT: [[T2:%.*]] = and <1 x i32> [[X]], +; CHECK-NEXT: [[T3:%.*]] = icmp ne <1 x i32> [[T2]], +; CHECK-NEXT: [[T4:%.*]] = and <1 x i1> [[T3]], [[T1]] +; CHECK-NEXT: ret <1 x i1> [[T4]] +; + %t1 = icmp ult <1 x i32> %x, + %t2 = and <1 x i32> %x, + %t3 = icmp ne <1 x i32> %t2, + %t4 = and <1 x i1> %t3, %t1 + ret <1 x i1> %t4 +} + +; Vector of 2 reduction +define <2 x i1> @masked_icmps_mask_allzeros_bmask_notmixed_and_notallones_15(<2 x i32> %x) { +; CHECK-LABEL: @masked_icmps_mask_allzeros_bmask_notmixed_and_notallones_15( +; CHECK-NEXT: [[T1:%.*]] = icmp sgt <2 x i32> [[X:%.*]], +; CHECK-NEXT: [[T2:%.*]] = and <2 x i32> [[X]], +; CHECK-NEXT: [[T3:%.*]] = icmp ne <2 x i32> [[T2]], +; CHECK-NEXT: [[T4:%.*]] = and <2 x i1> [[T1]], [[T3]] +; CHECK-NEXT: ret <2 x i1> [[T4]] +; + %t1 = icmp ult <2 x i32> %x, + %t2 = and <2 x i32> %x, + %t3 = icmp ne <2 x i32> %t2, + %t4 = and <2 x i1> %t1, %t3 + ret <2 x i1> %t4 +} + +define <2 x i1> @masked_icmps_mask_allzeros_bmask_notmixed_and_notallones_swapped_15(<2 x i32> %x) { +; CHECK-LABEL: @masked_icmps_mask_allzeros_bmask_notmixed_and_notallones_swapped_15( +; CHECK-NEXT: [[T1:%.*]] = icmp sgt <2 x i32> [[X:%.*]], +; CHECK-NEXT: [[T2:%.*]] = and <2 x i32> [[X]], +; CHECK-NEXT: [[T3:%.*]] = icmp ne <2 x i32> [[T2]], +; CHECK-NEXT: [[T4:%.*]] = and <2 x i1> [[T3]], [[T1]] +; CHECK-NEXT: ret <2 x i1> [[T4]] +; + %t1 = icmp ult <2 x i32> %x, + %t2 = and <2 x i32> %x, + %t3 = icmp ne <2 x i32> %t2, + %t4 = and <2 x i1> %t3, %t1 + ret <2 x i1> %t4 +} + +; Vector of 2 reduction with splat containing poison +define <2 x i1> @masked_icmps_mask_allzeros_bmask_notmixed_and_notallones_16(<2 x i32> %x) { +; CHECK-LABEL: @masked_icmps_mask_allzeros_bmask_notmixed_and_notallones_16( +; CHECK-NEXT: [[T1:%.*]] = icmp ult <2 x i32> [[X:%.*]], +; CHECK-NEXT: [[T2:%.*]] = and <2 x i32> [[X]], +; CHECK-NEXT: [[T3:%.*]] = icmp ne <2 x i32> [[T2]], +; CHECK-NEXT: [[T4:%.*]] = and <2 x i1> [[T1]], [[T3]] +; CHECK-NEXT: ret <2 x i1> [[T4]] +; + %t1 = icmp ult <2 x i32> %x, + %t2 = and <2 x i32> %x, + %t3 = icmp ne <2 x i32> %t2, + %t4 = and <2 x i1> %t1, %t3 + ret <2 x i1> %t4 +} + +; Vector of 7 reduction +define <7 x i1> @masked_icmps_mask_allzeros_bmask_notmixed_and_notallones_17(<7 x i8> %x) { +; CHECK-LABEL: @masked_icmps_mask_allzeros_bmask_notmixed_and_notallones_17( +; CHECK-NEXT: [[T1:%.*]] = icmp sgt <7 x i8> [[X:%.*]], +; CHECK-NEXT: [[T2:%.*]] = and <7 x i8> [[X]], +; CHECK-NEXT: [[T3:%.*]] = icmp ne <7 x i8> [[T2]], +; CHECK-NEXT: [[T4:%.*]] = and <7 x i1> [[T1]], [[T3]] +; CHECK-NEXT: ret <7 x i1> [[T4]] +; + %t1 = icmp ult <7 x i8> %x, + %t2 = and <7 x i8> %x, + %t3 = icmp ne <7 x i8> %t2, + %t4 = and <7 x i1> %t1, %t3 + ret <7 x i1> %t4 +} + +define <7 x i1> @masked_icmps_mask_allzeros_bmask_notmixed_and_notallones_swapped_17(<7 x i8> %x) { +; CHECK-LABEL: @masked_icmps_mask_allzeros_bmask_notmixed_and_notallones_swapped_17( +; CHECK-NEXT: [[T1:%.*]] = icmp sgt <7 x i8> [[X:%.*]], +; CHECK-NEXT: [[T2:%.*]] = and <7 x i8> [[X]], +; CHECK-NEXT: [[T3:%.*]] = icmp ne <7 x i8> [[T2]], +; CHECK-NEXT: [[T4:%.*]] = and <7 x i1> [[T3]], [[T1]] +; CHECK-NEXT: ret <7 x i1> [[T4]] +; + %t1 = icmp ult <7 x i8> %x, + %t2 = and <7 x i8> %x, + %t3 = icmp ne <7 x i8> %t2, + %t4 = and <7 x i1> %t3, %t1 + ret <7 x i1> %t4 +} + +; Vector of 6 reduction +define <6 x i1> @masked_icmps_mask_allzeros_bmask_notmixed_and_notallones_18(<6 x i8> %x) { +; CHECK-LABEL: @masked_icmps_mask_allzeros_bmask_notmixed_and_notallones_18( +; CHECK-NEXT: [[T1:%.*]] = icmp ult <6 x i8> [[X:%.*]], +; CHECK-NEXT: [[T2:%.*]] = and <6 x i8> [[X]], +; CHECK-NEXT: [[T3:%.*]] = icmp ne <6 x i8> [[T2]], +; CHECK-NEXT: [[T4:%.*]] = and <6 x i1> [[T1]], [[T3]] +; CHECK-NEXT: ret <6 x i1> [[T4]] +; + %t1 = icmp ult <6 x i8> %x, + %t2 = and <6 x i8> %x, + %t3 = icmp ne <6 x i8> %t2, + %t4 = and <6 x i1> %t1, %t3 + ret <6 x i1> %t4 +} + +define <6 x i1> @masked_icmps_mask_allzeros_bmask_notmixed_and_notallones_swapped_18(<6 x i8> %x) { +; CHECK-LABEL: @masked_icmps_mask_allzeros_bmask_notmixed_and_notallones_swapped_18( +; CHECK-NEXT: [[T1:%.*]] = icmp ult <6 x i8> [[X:%.*]], +; CHECK-NEXT: [[T2:%.*]] = and <6 x i8> [[X]], +; CHECK-NEXT: [[T3:%.*]] = icmp ne <6 x i8> [[T2]], +; CHECK-NEXT: [[T4:%.*]] = and <6 x i1> [[T1]], [[T3]] +; CHECK-NEXT: ret <6 x i1> [[T4]] +; + %t1 = icmp ult <6 x i8> %x, + %t2 = and <6 x i8> %x, + %t3 = icmp ne <6 x i8> %t2, + %t4 = and <6 x i1> %t1, %t3 + ret <6 x i1> %t4 +} + +; Vector of 0 of 1 compatible, no change +define <1 x i1> @masked_icmps_mask_allzeros_bmask_notmixed_and_notallones_19(<1 x i32> %x) { +; CHECK-LABEL: @masked_icmps_mask_allzeros_bmask_notmixed_and_notallones_19( +; CHECK-NEXT: [[T1:%.*]] = icmp sgt <1 x i32> [[X:%.*]], +; CHECK-NEXT: [[T2:%.*]] = and <1 x i32> [[X]], +; CHECK-NEXT: [[T3:%.*]] = icmp ne <1 x i32> [[T2]], +; CHECK-NEXT: [[T4:%.*]] = and <1 x i1> [[T1]], [[T3]] +; CHECK-NEXT: ret <1 x i1> [[T4]] +; + %t1 = icmp ult <1 x i32> %x, + %t2 = and <1 x i32> %x, + %t3 = icmp ne <1 x i32> %t2, + %t4 = and <1 x i1> %t1, %t3 + ret <1 x i1> %t4 +} + +define <1 x i1> @masked_icmps_mask_allzeros_bmask_notmixed_and_notallones_swapped_19(<1 x i32> %x) { +; CHECK-LABEL: @masked_icmps_mask_allzeros_bmask_notmixed_and_notallones_swapped_19( +; CHECK-NEXT: [[T1:%.*]] = icmp sgt <1 x i32> [[X:%.*]], +; CHECK-NEXT: [[T2:%.*]] = and <1 x i32> [[X]], +; CHECK-NEXT: [[T3:%.*]] = icmp ne <1 x i32> [[T2]], +; CHECK-NEXT: [[T4:%.*]] = and <1 x i1> [[T3]], [[T1]] +; CHECK-NEXT: ret <1 x i1> [[T4]] +; + %t1 = icmp ult <1 x i32> %x, + %t2 = and <1 x i32> %x, + %t3 = icmp ne <1 x i32> %t2, + %t4 = and <1 x i1> %t3, %t1 + ret <1 x i1> %t4 +} + +; Vector 1 of 2 compatible, no change +define <2 x i1> @masked_icmps_mask_allzeros_bmask_notmixed_and_notallones_20(<2 x i32> %x) { +; CHECK-LABEL: @masked_icmps_mask_allzeros_bmask_notmixed_and_notallones_20( +; CHECK-NEXT: [[T1:%.*]] = icmp sgt <2 x i32> [[X:%.*]], +; CHECK-NEXT: [[T2:%.*]] = and <2 x i32> [[X]], +; CHECK-NEXT: [[T3:%.*]] = icmp ne <2 x i32> [[T2]], +; CHECK-NEXT: [[T4:%.*]] = and <2 x i1> [[T1]], [[T3]] +; CHECK-NEXT: ret <2 x i1> [[T4]] +; + %t1 = icmp ult <2 x i32> %x, + %t2 = and <2 x i32> %x, + %t3 = icmp ne <2 x i32> %t2, + %t4 = and <2 x i1> %t1, %t3 + ret <2 x i1> %t4 +} + +define <2 x i1> @masked_icmps_mask_allzeros_bmask_notmixed_and_notallones_swapped_20(<2 x i32> %x) { +; CHECK-LABEL: @masked_icmps_mask_allzeros_bmask_notmixed_and_notallones_swapped_20( +; CHECK-NEXT: [[T1:%.*]] = icmp sgt <2 x i32> [[X:%.*]], +; CHECK-NEXT: [[T2:%.*]] = and <2 x i32> [[X]], +; CHECK-NEXT: [[T3:%.*]] = icmp ne <2 x i32> [[T2]], +; CHECK-NEXT: [[T4:%.*]] = and <2 x i1> [[T3]], [[T1]] +; CHECK-NEXT: ret <2 x i1> [[T4]] +; + %t1 = icmp ult <2 x i32> %x, + %t2 = and <2 x i32> %x, + %t3 = icmp ne <2 x i32> %t2, + %t4 = and <2 x i1> %t3, %t1 + ret <2 x i1> %t4 +} + +; Vector 6 of 7 compatible, no change +define <7 x i1> @masked_icmps_mask_allzeros_bmask_notmixed_and_notallones_21(<7 x i8> %x) { +; CHECK-LABEL: @masked_icmps_mask_allzeros_bmask_notmixed_and_notallones_21( +; CHECK-NEXT: [[T1:%.*]] = icmp sgt <7 x i8> [[X:%.*]], +; CHECK-NEXT: [[T2:%.*]] = and <7 x i8> [[X]], +; CHECK-NEXT: [[T3:%.*]] = icmp ne <7 x i8> [[T2]], +; CHECK-NEXT: [[T4:%.*]] = and <7 x i1> [[T1]], [[T3]] +; CHECK-NEXT: ret <7 x i1> [[T4]] +; + %t1 = icmp ult <7 x i8> %x, + %t2 = and <7 x i8> %x, + %t3 = icmp ne <7 x i8> %t2, + %t4 = and <7 x i1> %t1, %t3 + ret <7 x i1> %t4 +} + +define <7 x i1> @masked_icmps_mask_allzeros_bmask_notmixed_and_notallones_swapped_21(<7 x i8> %x) { +; CHECK-LABEL: @masked_icmps_mask_allzeros_bmask_notmixed_and_notallones_swapped_21( +; CHECK-NEXT: [[T1:%.*]] = icmp sgt <7 x i8> [[X:%.*]], +; CHECK-NEXT: [[T2:%.*]] = and <7 x i8> [[X]], +; CHECK-NEXT: [[T3:%.*]] = icmp ne <7 x i8> [[T2]], +; CHECK-NEXT: [[T4:%.*]] = and <7 x i1> [[T3]], [[T1]] +; CHECK-NEXT: ret <7 x i1> [[T4]] +; + %t1 = icmp ult <7 x i8> %x, + %t2 = and <7 x i8> %x, + %t3 = icmp ne <7 x i8> %t2, + %t4 = and <7 x i1> %t3, %t1 + ret <7 x i1> %t4 +} + +; Vector 0 of 6 compatible, no change +define <6 x i1> @masked_icmps_mask_allzeros_bmask_notmixed_and_notallones_22(<6 x i8> %x) { +; CHECK-LABEL: @masked_icmps_mask_allzeros_bmask_notmixed_and_notallones_22( +; CHECK-NEXT: [[T1:%.*]] = icmp sgt <6 x i8> [[X:%.*]], +; CHECK-NEXT: [[T2:%.*]] = and <6 x i8> [[X]], +; CHECK-NEXT: [[T3:%.*]] = icmp ne <6 x i8> [[T2]], +; CHECK-NEXT: [[T4:%.*]] = and <6 x i1> [[T1]], [[T3]] +; CHECK-NEXT: ret <6 x i1> [[T4]] +; + %t1 = icmp ult <6 x i8> %x, + %t2 = and <6 x i8> %x, + %t3 = icmp ne <6 x i8> %t2, + %t4 = and <6 x i1> %t1, %t3 + ret <6 x i1> %t4 +} + +define <6 x i1> @masked_icmps_mask_allzeros_bmask_notmixed_and_notallones_swapped_22(<6 x i8> %x) { +; CHECK-LABEL: @masked_icmps_mask_allzeros_bmask_notmixed_and_notallones_swapped_22( +; CHECK-NEXT: [[T1:%.*]] = icmp sgt <6 x i8> [[X:%.*]], +; CHECK-NEXT: [[T2:%.*]] = and <6 x i8> [[X]], +; CHECK-NEXT: [[T3:%.*]] = icmp ne <6 x i8> [[T2]], +; CHECK-NEXT: [[T4:%.*]] = and <6 x i1> [[T3]], [[T1]] +; CHECK-NEXT: ret <6 x i1> [[T4]] +; + %t1 = icmp ult <6 x i8> %x, + %t2 = and <6 x i8> %x, + %t3 = icmp ne <6 x i8> %t2, + %t4 = and <6 x i1> %t3, %t1 + ret <6 x i1> %t4 +}