148c6b272SRoman Lebedev; RUN: opt -passes=loop-idiom -S < %s | FileCheck %s 2cee313d2SEric Christopher 3cee313d2SEric Christophertarget datalayout = "e-m:o-i64:64-i128:128-n32:64-S128" 4cee313d2SEric Christophertarget triple = "arm64-apple-ios8.0.0" 5cee313d2SEric Christopher 6cee313d2SEric Christopher; When we replace the precondition with a ctpop, we need to ensure 7cee313d2SEric Christopher; that only the first branch reads the ctpop. The store prior 8cee313d2SEric Christopher; to that should continue to read from the original compare. 9cee313d2SEric Christopher 10cee313d2SEric Christopher; CHECK: %tobool.5 = icmp ne i32 %num, 0 11*055fb779SNikita Popov; CHECK: store i1 %tobool.5, ptr %ptr 12cee313d2SEric Christopher 13*055fb779SNikita Popovdefine internal fastcc i32 @num_bits_set(i32 %num, ptr %ptr) #1 { 14cee313d2SEric Christopherentry: 15cee313d2SEric Christopher %tobool.5 = icmp ne i32 %num, 0 16*055fb779SNikita Popov store i1 %tobool.5, ptr %ptr 17cee313d2SEric Christopher br i1 %tobool.5, label %for.body.lr.ph, label %for.end 18cee313d2SEric Christopher 19cee313d2SEric Christopherfor.body.lr.ph: ; preds = %entry 20cee313d2SEric Christopher br label %for.body 21cee313d2SEric Christopher 22cee313d2SEric Christopherfor.body: ; preds = %for.body.lr.ph, %for.body 23cee313d2SEric Christopher %count.07 = phi i32 [ 0, %for.body.lr.ph ], [ %inc, %for.body ] 24cee313d2SEric Christopher %num.addr.06 = phi i32 [ %num, %for.body.lr.ph ], [ %and, %for.body ] 25cee313d2SEric Christopher %sub = add i32 %num.addr.06, -1 26cee313d2SEric Christopher %and = and i32 %sub, %num.addr.06 27cee313d2SEric Christopher %inc = add nsw i32 %count.07, 1 28cee313d2SEric Christopher %tobool = icmp ne i32 %and, 0 29cee313d2SEric Christopher br i1 %tobool, label %for.body, label %for.end 30cee313d2SEric Christopher 31cee313d2SEric Christopherfor.end: ; preds = %for.cond.for.end_crit_edge, %entry 32cee313d2SEric Christopher %count.0.lcssa = phi i32 [ %inc, %for.body ], [ 0, %entry ] 33cee313d2SEric Christopher ret i32 %count.0.lcssa 34cee313d2SEric Christopher} 35