; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt -S < %s -passes=simplifycfg -simplifycfg-require-and-preserve-domtree=1 -simplifycfg-merge-cond-stores=true -simplifycfg-merge-cond-stores-aggressively=false -phi-node-folding-threshold=1 | FileCheck %s
target datalayout = "e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64"
target triple = "armv7--linux-gnueabihf"
; This is a bit reversal that has been run through the early optimizer (-mem2reg -passes=gvn -instcombine).
; There should be no additional PHIs created at all. The store should be on its own in a predicated
; block and there should be no PHIs.
define i32 @f(ptr %b) {
; CHECK-LABEL: @f(
; CHECK-NEXT: entry:
; CHECK-NEXT: [[TMP0:%.*]] = load i32, ptr [[B:%.*]], align 4
; CHECK-NEXT: [[AND:%.*]] = and i32 [[TMP0]], 1
; CHECK-NEXT: [[TOBOOL:%.*]] = icmp eq i32 [[AND]], 0
; CHECK-NEXT: [[OR:%.*]] = or i32 [[TMP0]], -2147483648
; CHECK-NEXT: [[TMP1:%.*]] = select i1 [[TOBOOL]], i32 [[TMP0]], i32 [[OR]]
; CHECK-NEXT: [[AND1:%.*]] = and i32 [[TMP1]], 2
; CHECK-NEXT: [[TOBOOL2:%.*]] = icmp eq i32 [[AND1]], 0
; CHECK-NEXT: [[OR4:%.*]] = or i32 [[TMP1]], 1073741824
; CHECK-NEXT: [[TMP2:%.*]] = select i1 [[TOBOOL2]], i32 [[TMP1]], i32 [[OR4]]
; CHECK-NEXT: [[TMP3:%.*]] = xor i1 [[TOBOOL]], true
; CHECK-NEXT: [[TMP4:%.*]] = xor i1 [[TOBOOL2]], true
; CHECK-NEXT: [[TMP5:%.*]] = or i1 [[TMP3]], [[TMP4]]
; CHECK-NEXT: [[AND6:%.*]] = and i32 [[TMP2]], 4
; CHECK-NEXT: [[TOBOOL7:%.*]] = icmp eq i32 [[AND6]], 0
; CHECK-NEXT: [[OR9:%.*]] = or i32 [[TMP2]], 536870912
; CHECK-NEXT: [[SPEC_SELECT:%.*]] = select i1 [[TOBOOL7]], i32 [[TMP2]], i32 [[OR9]]
; CHECK-NEXT: [[TMP6:%.*]] = xor i1 [[TMP5]], true
; CHECK-NEXT: [[TMP7:%.*]] = xor i1 [[TOBOOL7]], true
; CHECK-NEXT: [[TMP8:%.*]] = xor i1 [[TMP6]], true
; CHECK-NEXT: [[TMP9:%.*]] = or i1 [[TMP8]], [[TMP7]]
; CHECK-NEXT: [[AND11:%.*]] = and i32 [[SPEC_SELECT]], 8
; CHECK-NEXT: [[TOBOOL12:%.*]] = icmp eq i32 [[AND11]], 0
; CHECK-NEXT: [[OR14:%.*]] = or i32 [[SPEC_SELECT]], 268435456
; CHECK-NEXT: [[SPEC_SELECT1:%.*]] = select i1 [[TOBOOL12]], i32 [[SPEC_SELECT]], i32 [[OR14]]
; CHECK-NEXT: [[TMP10:%.*]] = xor i1 [[TMP9]], true
; CHECK-NEXT: [[TMP11:%.*]] = xor i1 [[TOBOOL12]], true
; CHECK-NEXT: [[TMP12:%.*]] = xor i1 [[TMP10]], true
; CHECK-NEXT: [[TMP13:%.*]] = or i1 [[TMP12]], [[TMP11]]
; CHECK-NEXT: [[AND16:%.*]] = and i32 [[SPEC_SELECT1]], 16
; CHECK-NEXT: [[TOBOOL17:%.*]] = icmp eq i32 [[AND16]], 0
; CHECK-NEXT: [[OR19:%.*]] = or i32 [[SPEC_SELECT1]], 134217728
; CHECK-NEXT: [[SPEC_SELECT2:%.*]] = select i1 [[TOBOOL17]], i32 [[SPEC_SELECT1]], i32 [[OR19]]
; CHECK-NEXT: [[TMP14:%.*]] = xor i1 [[TMP13]], true
; CHECK-NEXT: [[TMP15:%.*]] = xor i1 [[TOBOOL17]], true
; CHECK-NEXT: [[TMP16:%.*]] = xor i1 [[TMP14]], true
; CHECK-NEXT: [[TMP17:%.*]] = or i1 [[TMP16]], [[TMP15]]
; CHECK-NEXT: [[AND21:%.*]] = and i32 [[SPEC_SELECT2]], 32
; CHECK-NEXT: [[TOBOOL22:%.*]] = icmp eq i32 [[AND21]], 0
; CHECK-NEXT: [[OR24:%.*]] = or i32 [[SPEC_SELECT2]], 67108864
; CHECK-NEXT: [[SPEC_SELECT3:%.*]] = select i1 [[TOBOOL22]], i32 [[SPEC_SELECT2]], i32 [[OR24]]
; CHECK-NEXT: [[TMP18:%.*]] = xor i1 [[TMP17]], true
; CHECK-NEXT: [[TMP19:%.*]] = xor i1 [[TOBOOL22]], true
; CHECK-NEXT: [[TMP20:%.*]] = xor i1 [[TMP18]], true
; CHECK-NEXT: [[TMP21:%.*]] = or i1 [[TMP20]], [[TMP19]]
; CHECK-NEXT: [[AND26:%.*]] = and i32 [[SPEC_SELECT3]], 64
; CHECK-NEXT: [[TOBOOL27:%.*]] = icmp eq i32 [[AND26]], 0
; CHECK-NEXT: [[OR29:%.*]] = or i32 [[SPEC_SELECT3]], 33554432
; CHECK-NEXT: [[SPEC_SELECT4:%.*]] = select i1 [[TOBOOL27]], i32 [[SPEC_SELECT3]], i32 [[OR29]]
; CHECK-NEXT: [[TMP22:%.*]] = xor i1 [[TMP21]], true
; CHECK-NEXT: [[TMP23:%.*]] = xor i1 [[TOBOOL27]], true
; CHECK-NEXT: [[TMP24:%.*]] = xor i1 [[TMP22]], true
; CHECK-NEXT: [[TMP25:%.*]] = or i1 [[TMP24]], [[TMP23]]
; CHECK-NEXT: [[AND31:%.*]] = and i32 [[SPEC_SELECT4]], 256
; CHECK-NEXT: [[TOBOOL32:%.*]] = icmp eq i32 [[AND31]], 0
; CHECK-NEXT: [[OR34:%.*]] = or i32 [[SPEC_SELECT4]], 8388608
; CHECK-NEXT: [[SPEC_SELECT5:%.*]] = select i1 [[TOBOOL32]], i32 [[SPEC_SELECT4]], i32 [[OR34]]
; CHECK-NEXT: [[TMP26:%.*]] = xor i1 [[TMP25]], true
; CHECK-NEXT: [[TMP27:%.*]] = xor i1 [[TOBOOL32]], true
; CHECK-NEXT: [[TMP28:%.*]] = xor i1 [[TMP26]], true
; CHECK-NEXT: [[TMP29:%.*]] = or i1 [[TMP28]], [[TMP27]]
; CHECK-NEXT: [[AND36:%.*]] = and i32 [[SPEC_SELECT5]], 512
; CHECK-NEXT: [[TOBOOL37:%.*]] = icmp eq i32 [[AND36]], 0
; CHECK-NEXT: [[OR39:%.*]] = or i32 [[SPEC_SELECT5]], 4194304
; CHECK-NEXT: [[SPEC_SELECT6:%.*]] = select i1 [[TOBOOL37]], i32 [[SPEC_SELECT5]], i32 [[OR39]]
; CHECK-NEXT: [[TMP30:%.*]] = xor i1 [[TMP29]], true
; CHECK-NEXT: [[TMP31:%.*]] = xor i1 [[TOBOOL37]], true
; CHECK-NEXT: [[TMP32:%.*]] = xor i1 [[TMP30]], true
; CHECK-NEXT: [[TMP33:%.*]] = or i1 [[TMP32]], [[TMP31]]
; CHECK-NEXT: [[AND41:%.*]] = and i32 [[SPEC_SELECT6]], 1024
; CHECK-NEXT: [[TOBOOL42:%.*]] = icmp eq i32 [[AND41]], 0
; CHECK-NEXT: [[OR44:%.*]] = or i32 [[SPEC_SELECT6]], 2097152
; CHECK-NEXT: [[SPEC_SELECT7:%.*]] = select i1 [[TOBOOL42]], i32 [[SPEC_SELECT6]], i32 [[OR44]]
; CHECK-NEXT: [[TMP34:%.*]] = xor i1 [[TMP33]], true
; CHECK-NEXT: [[TMP35:%.*]] = xor i1 [[TOBOOL42]], true
; CHECK-NEXT: [[TMP36:%.*]] = xor i1 [[TMP34]], true
; CHECK-NEXT: [[TMP37:%.*]] = or i1 [[TMP36]], [[TMP35]]
; CHECK-NEXT: [[AND46:%.*]] = and i32 [[SPEC_SELECT7]], 2048
; CHECK-NEXT: [[TOBOOL47:%.*]] = icmp eq i32 [[AND46]], 0
; CHECK-NEXT: [[OR49:%.*]] = or i32 [[SPEC_SELECT7]], 1048576
; CHECK-NEXT: [[SPEC_SELECT8:%.*]] = select i1 [[TOBOOL47]], i32 [[SPEC_SELECT7]], i32 [[OR49]]
; CHECK-NEXT: [[TMP38:%.*]] = xor i1 [[TMP37]], true
; CHECK-NEXT: [[TMP39:%.*]] = xor i1 [[TOBOOL47]], true
; CHECK-NEXT: [[TMP40:%.*]] = xor i1 [[TMP38]], true
; CHECK-NEXT: [[TMP41:%.*]] = or i1 [[TMP40]], [[TMP39]]
; CHECK-NEXT: [[AND51:%.*]] = and i32 [[SPEC_SELECT8]], 4096
; CHECK-NEXT: [[TOBOOL52:%.*]] = icmp eq i32 [[AND51]], 0
; CHECK-NEXT: [[OR54:%.*]] = or i32 [[SPEC_SELECT8]], 524288
; CHECK-NEXT: [[SPEC_SELECT9:%.*]] = select i1 [[TOBOOL52]], i32 [[SPEC_SELECT8]], i32 [[OR54]]
; CHECK-NEXT: [[TMP42:%.*]] = xor i1 [[TMP41]], true
; CHECK-NEXT: [[TMP43:%.*]] = xor i1 [[TOBOOL52]], true
; CHECK-NEXT: [[TMP44:%.*]] = xor i1 [[TMP42]], true
; CHECK-NEXT: [[TMP45:%.*]] = or i1 [[TMP44]], [[TMP43]]
; CHECK-NEXT: [[AND56:%.*]] = and i32 [[SPEC_SELECT9]], 8192
; CHECK-NEXT: [[TOBOOL57:%.*]] = icmp eq i32 [[AND56]], 0
; CHECK-NEXT: [[OR59:%.*]] = or i32 [[SPEC_SELECT9]], 262144
; CHECK-NEXT: [[SPEC_SELECT10:%.*]] = select i1 [[TOBOOL57]], i32 [[SPEC_SELECT9]], i32 [[OR59]]
; CHECK-NEXT: [[TMP46:%.*]] = xor i1 [[TMP45]], true
; CHECK-NEXT: [[TMP47:%.*]] = xor i1 [[TOBOOL57]], true
; CHECK-NEXT: [[TMP48:%.*]] = xor i1 [[TMP46]], true
; CHECK-NEXT: [[TMP49:%.*]] = or i1 [[TMP48]], [[TMP47]]
; CHECK-NEXT: [[AND61:%.*]] = and i32 [[SPEC_SELECT10]], 16384
; CHECK-NEXT: [[TOBOOL62:%.*]] = icmp eq i32 [[AND61]], 0
; CHECK-NEXT: [[OR64:%.*]] = or i32 [[SPEC_SELECT10]], 131072
; CHECK-NEXT: [[SPEC_SELECT11:%.*]] = select i1 [[TOBOOL62]], i32 [[SPEC_SELECT10]], i32 [[OR64]]
; CHECK-NEXT: [[TMP50:%.*]] = xor i1 [[TMP49]], true
; CHECK-NEXT: [[TMP51:%.*]] = xor i1 [[TOBOOL62]], true
; CHECK-NEXT: [[TMP52:%.*]] = xor i1 [[TMP50]], true
; CHECK-NEXT: [[TMP53:%.*]] = or i1 [[TMP52]], [[TMP51]]
; CHECK-NEXT: [[AND66:%.*]] = and i32 [[SPEC_SELECT11]], 32768
; CHECK-NEXT: [[TOBOOL67:%.*]] = icmp eq i32 [[AND66]], 0
; CHECK-NEXT: [[OR69:%.*]] = or i32 [[SPEC_SELECT11]], 65536
; CHECK-NEXT: [[SPEC_SELECT12:%.*]] = select i1 [[TOBOOL67]], i32 [[SPEC_SELECT11]], i32 [[OR69]]
; CHECK-NEXT: [[TMP54:%.*]] = xor i1 [[TMP53]], true
; CHECK-NEXT: [[TMP55:%.*]] = xor i1 [[TOBOOL67]], true
; CHECK-NEXT: [[TMP56:%.*]] = xor i1 [[TMP54]], true
; CHECK-NEXT: [[TMP57:%.*]] = or i1 [[TMP56]], [[TMP55]]
; CHECK-NEXT: [[AND71:%.*]] = and i32 [[SPEC_SELECT12]], 128
; CHECK-NEXT: [[TOBOOL72:%.*]] = icmp eq i32 [[AND71]], 0
; CHECK-NEXT: [[OR74:%.*]] = or i32 [[SPEC_SELECT12]], 16777216
; CHECK-NEXT: [[SPEC_SELECT13:%.*]] = select i1 [[TOBOOL72]], i32 [[SPEC_SELECT12]], i32 [[OR74]]
; CHECK-NEXT: [[TMP58:%.*]] = xor i1 [[TMP57]], true
; CHECK-NEXT: [[TMP59:%.*]] = xor i1 [[TOBOOL72]], true
; CHECK-NEXT: [[TMP60:%.*]] = xor i1 [[TMP58]], true
; CHECK-NEXT: [[TMP61:%.*]] = or i1 [[TMP60]], [[TMP59]]
; CHECK-NEXT: br i1 [[TMP61]], label [[TMP62:%.*]], label [[TMP63:%.*]]
; CHECK: 62:
; CHECK-NEXT: store i32 [[SPEC_SELECT13]], ptr [[B]], align 4
; CHECK-NEXT: br label [[TMP63]]
; CHECK: 63:
; CHECK-NEXT: ret i32 0
;
entry:
%0 = load i32, ptr %b, align 4
%and = and i32 %0, 1
%tobool = icmp eq i32 %and, 0
br i1 %tobool, label %if.end, label %if.then
if.then: ; preds = %entry
%or = or i32 %0, -2147483648
store i32 %or, ptr %b, align 4
br label %if.end
if.end: ; preds = %entry, %if.then
%1 = phi i32 [ %0, %entry ], [ %or, %if.then ]
%and1 = and i32 %1, 2
%tobool2 = icmp eq i32 %and1, 0
br i1 %tobool2, label %if.end5, label %if.then3
if.then3: ; preds = %if.end
%or4 = or i32 %1, 1073741824
store i32 %or4, ptr %b, align 4
br label %if.end5
if.end5: ; preds = %if.end, %if.then3
%2 = phi i32 [ %1, %if.end ], [ %or4, %if.then3 ]
%and6 = and i32 %2, 4
%tobool7 = icmp eq i32 %and6, 0
br i1 %tobool7, label %if.end10, label %if.then8
if.then8: ; preds = %if.end5
%or9 = or i32 %2, 536870912
store i32 %or9, ptr %b, align 4
br label %if.end10
if.end10: ; preds = %if.end5, %if.then8
%3 = phi i32 [ %2, %if.end5 ], [ %or9, %if.then8 ]
%and11 = and i32 %3, 8
%tobool12 = icmp eq i32 %and11, 0
br i1 %tobool12, label %if.end15, label %if.then13
if.then13: ; preds = %if.end10
%or14 = or i32 %3, 268435456
store i32 %or14, ptr %b, align 4
br label %if.end15
if.end15: ; preds = %if.end10, %if.then13
%4 = phi i32 [ %3, %if.end10 ], [ %or14, %if.then13 ]
%and16 = and i32 %4, 16
%tobool17 = icmp eq i32 %and16, 0
br i1 %tobool17, label %if.end20, label %if.then18
if.then18: ; preds = %if.end15
%or19 = or i32 %4, 134217728
store i32 %or19, ptr %b, align 4
br label %if.end20
if.end20: ; preds = %if.end15, %if.then18
%5 = phi i32 [ %4, %if.end15 ], [ %or19, %if.then18 ]
%and21 = and i32 %5, 32
%tobool22 = icmp eq i32 %and21, 0
br i1 %tobool22, label %if.end25, label %if.then23
if.then23: ; preds = %if.end20
%or24 = or i32 %5, 67108864
store i32 %or24, ptr %b, align 4
br label %if.end25
if.end25: ; preds = %if.end20, %if.then23
%6 = phi i32 [ %5, %if.end20 ], [ %or24, %if.then23 ]
%and26 = and i32 %6, 64
%tobool27 = icmp eq i32 %and26, 0
br i1 %tobool27, label %if.end30, label %if.then28
if.then28: ; preds = %if.end25
%or29 = or i32 %6, 33554432
store i32 %or29, ptr %b, align 4
br label %if.end30
if.end30: ; preds = %if.end25, %if.then28
%7 = phi i32 [ %6, %if.end25 ], [ %or29, %if.then28 ]
%and31 = and i32 %7, 256
%tobool32 = icmp eq i32 %and31, 0
br i1 %tobool32, label %if.end35, label %if.then33
if.then33: ; preds = %if.end30
%or34 = or i32 %7, 8388608
store i32 %or34, ptr %b, align 4
br label %if.end35
if.end35: ; preds = %if.end30, %if.then33
%8 = phi i32 [ %7, %if.end30 ], [ %or34, %if.then33 ]
%and36 = and i32 %8, 512
%tobool37 = icmp eq i32 %and36, 0
br i1 %tobool37, label %if.end40, label %if.then38
if.then38: ; preds = %if.end35
%or39 = or i32 %8, 4194304
store i32 %or39, ptr %b, align 4
br label %if.end40
if.end40: ; preds = %if.end35, %if.then38
%9 = phi i32 [ %8, %if.end35 ], [ %or39, %if.then38 ]
%and41 = and i32 %9, 1024
%tobool42 = icmp eq i32 %and41, 0
br i1 %tobool42, label %if.end45, label %if.then43
if.then43: ; preds = %if.end40
%or44 = or i32 %9, 2097152
store i32 %or44, ptr %b, align 4
br label %if.end45
if.end45: ; preds = %if.end40, %if.then43
%10 = phi i32 [ %9, %if.end40 ], [ %or44, %if.then43 ]
%and46 = and i32 %10, 2048
%tobool47 = icmp eq i32 %and46, 0
br i1 %tobool47, label %if.end50, label %if.then48
if.then48: ; preds = %if.end45
%or49 = or i32 %10, 1048576
store i32 %or49, ptr %b, align 4
br label %if.end50
if.end50: ; preds = %if.end45, %if.then48
%11 = phi i32 [ %10, %if.end45 ], [ %or49, %if.then48 ]
%and51 = and i32 %11, 4096
%tobool52 = icmp eq i32 %and51, 0
br i1 %tobool52, label %if.end55, label %if.then53
if.then53: ; preds = %if.end50
%or54 = or i32 %11, 524288
store i32 %or54, ptr %b, align 4
br label %if.end55
if.end55: ; preds = %if.end50, %if.then53
%12 = phi i32 [ %11, %if.end50 ], [ %or54, %if.then53 ]
%and56 = and i32 %12, 8192
%tobool57 = icmp eq i32 %and56, 0
br i1 %tobool57, label %if.end60, label %if.then58
if.then58: ; preds = %if.end55
%or59 = or i32 %12, 262144
store i32 %or59, ptr %b, align 4
br label %if.end60
if.end60: ; preds = %if.end55, %if.then58
%13 = phi i32 [ %12, %if.end55 ], [ %or59, %if.then58 ]
%and61 = and i32 %13, 16384
%tobool62 = icmp eq i32 %and61, 0
br i1 %tobool62, label %if.end65, label %if.then63
if.then63: ; preds = %if.end60
%or64 = or i32 %13, 131072
store i32 %or64, ptr %b, align 4
br label %if.end65
if.end65: ; preds = %if.end60, %if.then63
%14 = phi i32 [ %13, %if.end60 ], [ %or64, %if.then63 ]
%and66 = and i32 %14, 32768
%tobool67 = icmp eq i32 %and66, 0
br i1 %tobool67, label %if.end70, label %if.then68
if.then68: ; preds = %if.end65
%or69 = or i32 %14, 65536
store i32 %or69, ptr %b, align 4
br label %if.end70
if.end70: ; preds = %if.end65, %if.then68
%15 = phi i32 [ %14, %if.end65 ], [ %or69, %if.then68 ]
%and71 = and i32 %15, 128
%tobool72 = icmp eq i32 %and71, 0
br i1 %tobool72, label %if.end75, label %if.then73
if.then73: ; preds = %if.end70
%or74 = or i32 %15, 16777216
store i32 %or74, ptr %b, align 4
br label %if.end75
if.end75: ; preds = %if.end70, %if.then73
ret i32 0
}