diff --git a/include/llvm/Analysis/ConstantFolding.h b/include/llvm/Analysis/ConstantFolding.h index 52395804f11..50275a1df46 100644 --- a/include/llvm/Analysis/ConstantFolding.h +++ b/include/llvm/Analysis/ConstantFolding.h @@ -130,6 +130,17 @@ Constant *ConstantFoldCall(Function *F, ArrayRef Operands, bool AllowNonDeterministic = true); // HLSL Change End +// HLSL Change Begin +/// Attempt to constant fold the compare instruction \p I with the specified +/// operands. If \p AllowNonDeterministic is false, returns null instead of +/// folding a compare of a float denormal that the driver may flush to zero when +/// it executes \p I. +Constant *ConstantFoldCompareInstOperands(const Instruction *I, Constant *LHS, + Constant *RHS, const DataLayout &DL, + const TargetLibraryInfo *TLI, + bool AllowNonDeterministic); +// HLSL Change End + /// HLSL Change - make these functions external so we can call them from /// DxilConstantFolding.cpp. Constant *ConstantFoldFP(double(__cdecl *NativeFP)(double), double V, Type *Ty); diff --git a/lib/Analysis/ConstantFolding.cpp b/lib/Analysis/ConstantFolding.cpp index 6a4037a9ccb..0aa2d96cc89 100644 --- a/lib/Analysis/ConstantFolding.cpp +++ b/lib/Analysis/ConstantFolding.cpp @@ -39,6 +39,8 @@ #include "llvm/Analysis/DxilConstantFolding.h" // HLSL Change +#include "dxc/DXIL/DxilConstants.h" // HLSL Change + #ifdef HAVE_FENV_H #include #endif @@ -1022,6 +1024,38 @@ static bool isConstantNaN(const Constant *C) { return false; } +// HLSL Change End + +// HLSL Change Begin +// Returns true if \p C is a float denormal, or a vector with one as an element, +// that the driver may flush to zero when it executes \p I. It may unless the +// function's "fp32-denorm-mode" is "preserve", so folding it is +// non-deterministic. Half and double denormals are always kept. Upstream LLVM +// does not fold such denormals when the function's denormal mode is "dynamic". +static bool mayFlushDenormal(const Constant *C, const Instruction *I) { + if (const ConstantFP *CFP = dyn_cast(C)) { + if (!CFP->getType()->isFloatTy() || !CFP->getValueAPF().isDenormal()) + return false; + if (!I || !I->getParent()) + return true; + const Function *F = I->getParent()->getParent(); + return F->getFnAttribute(hlsl::DXIL::kFP32DenormKindString) + .getValueAsString() != + hlsl::DXIL::kFP32DenormValuePreserveString; + } + if (!C->getType()->isVectorTy()) + return false; + for (unsigned i = 0, e = C->getType()->getVectorNumElements(); i != e; ++i) { + const Constant *Elt = C->getAggregateElement(i); + if (Elt && mayFlushDenormal(Elt, I)) + return true; + } + return false; +} +// HLSL Change End + +// HLSL Change Begin - Backports +// https://github.com/llvm/llvm-project/commit/b6e102e08cd35543175459494211a3a15f793302 Constant *llvm::ConstantFoldInstOperands(unsigned Opcode, Type *DestTy, ArrayRef Ops, const DataLayout &DL, @@ -1057,9 +1091,11 @@ Constant *llvm::ConstantFoldInstOperands(unsigned Opcode, Type *DestTy, // https://github.com/llvm/llvm-project/commit/b6e102e08cd35543175459494211a3a15f793302 Constant *C = ConstantExpr::get(Opcode, Ops[0], Ops[1]); - // The precise NaN value is non-deterministic. - if (!AllowNonDeterministic && isConstantNaN(C)) - return nullptr; + // NaN bit patterns and flushable denormals are non-deterministic. + if (!AllowNonDeterministic) + if (isConstantNaN(C) || mayFlushDenormal(Ops[0], I) || + mayFlushDenormal(Ops[1], I) || mayFlushDenormal(C, I)) + return nullptr; return C; // HLSL Change End @@ -1118,8 +1154,10 @@ Constant *llvm::ConstantFoldInstOperands(unsigned Opcode, Type *DestTy, case Instruction::FPTrunc: case Instruction::FPExt: { Constant *C = ConstantExpr::getCast(Opcode, Ops[0], DestTy); - if (!AllowNonDeterministic && isConstantNaN(C)) - return nullptr; + if (!AllowNonDeterministic) + if (isConstantNaN(C) || mayFlushDenormal(Ops[0], I) || + mayFlushDenormal(C, I)) + return nullptr; return C; } // HLSL Change End @@ -1154,6 +1192,20 @@ Constant *llvm::ConstantFoldInstOperands(unsigned Opcode, Type *DestTy, } } +// HLSL Change Begin +Constant *llvm::ConstantFoldCompareInstOperands(const Instruction *I, + Constant *Ops0, Constant *Ops1, + const DataLayout &DL, + const TargetLibraryInfo *TLI, + bool AllowNonDeterministic) { + if (!AllowNonDeterministic && + (mayFlushDenormal(Ops0, I) || mayFlushDenormal(Ops1, I))) + return nullptr; + return ConstantFoldCompareInstOperands(cast(I)->getPredicate(), Ops0, + Ops1, DL, TLI); +} +// HLSL Change End + /// Attempt to constant fold a compare /// instruction (icmp/fcmp) with the specified operands. If it fails, it /// returns a constant expression of the specified operands. diff --git a/lib/Analysis/ScalarEvolution.cpp b/lib/Analysis/ScalarEvolution.cpp index 11700e8d111..97384b2f043 100644 --- a/lib/Analysis/ScalarEvolution.cpp +++ b/lib/Analysis/ScalarEvolution.cpp @@ -5501,8 +5501,10 @@ static Constant *EvaluateExpression(Value *V, const Loop *L, } if (CmpInst *CI = dyn_cast(I)) - return ConstantFoldCompareInstOperands(CI->getPredicate(), Operands[0], - Operands[1], DL, TLI); + // HLSL Change + return ConstantFoldCompareInstOperands(CI, Operands[0], Operands[1], DL, + TLI, + /*AllowNonDeterministic=*/false); if (LoadInst *LI = dyn_cast(I)) { if (!LI->isVolatile()) return ConstantFoldLoadFromConstPtr(Operands[0], DL); @@ -5948,8 +5950,10 @@ const SCEV *ScalarEvolution::computeSCEVAtScope(const SCEV *V, const Loop *L) { Constant *C = nullptr; const DataLayout &DL = F->getParent()->getDataLayout(); if (const CmpInst *CI = dyn_cast(I)) - C = ConstantFoldCompareInstOperands(CI->getPredicate(), Operands[0], - Operands[1], DL, TLI); + // HLSL Change + C = ConstantFoldCompareInstOperands( + CI, Operands[0], Operands[1], DL, TLI, + /*AllowNonDeterministic=*/false); else if (const LoadInst *LI = dyn_cast(I)) { if (!LI->isVolatile()) C = ConstantFoldLoadFromConstPtr(Operands[0], DL); diff --git a/tools/clang/test/DXC/Passes/IndVarSimplify/denorm-trip-count.ll b/tools/clang/test/DXC/Passes/IndVarSimplify/denorm-trip-count.ll new file mode 100644 index 00000000000..3cfd865a85b --- /dev/null +++ b/tools/clang/test/DXC/Passes/IndVarSimplify/denorm-trip-count.ll @@ -0,0 +1,302 @@ +; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 6 +; RUN: opt < %s -indvars -S | FileCheck %s + +; Check that ScalarEvolution does not evaluate a loop through a float denormal +; when "fp32-denorm-mode" does not say that denormals are kept, so +; IndVarSimplify keeps the loop bound, and that it does when the mode is +; "preserve". + +target datalayout = "e-m:e-p:32:32-i1:32-i8:32-i16:32-i32:32-i64:64-f16:32-f32:32-f64:64-n8:16:32:64" +target triple = "dxil-ms-dx" + +define i32 @denormal_fmul_any(i32 %stop) #0 { +; CHECK-LABEL: define i32 @denormal_fmul_any( +; CHECK-SAME: i32 [[STOP:%.*]]) #[[ATTR0:[0-9]+]] { +; CHECK-NEXT: [[ENTRY:.*]]: +; CHECK-NEXT: br label %[[LOOP:.*]] +; CHECK: [[LOOP]]: +; CHECK-NEXT: [[I:%.*]] = phi i32 [ 0, %[[ENTRY]] ], [ [[I_NEXT:%.*]], %[[LATCH:.*]] ] +; CHECK-NEXT: [[F:%.*]] = phi float [ 0x3820000000000000, %[[ENTRY]] ], [ [[F_NEXT:%.*]], %[[LATCH]] ] +; CHECK-NEXT: [[F_NEXT]] = fmul float [[F]], 5.000000e-01 +; CHECK-NEXT: [[SCALED:%.*]] = fmul float [[F_NEXT]], 0x47D0000000000000 +; CHECK-NEXT: [[FCMP:%.*]] = fcmp oeq float [[SCALED]], 5.000000e-01 +; CHECK-NEXT: [[SCMP:%.*]] = icmp eq i32 [[I]], [[STOP]] +; CHECK-NEXT: [[OR_COND:%.*]] = or i1 [[FCMP]], [[SCMP]] +; CHECK-NEXT: br i1 [[OR_COND]], label %[[EXIT:.*]], label %[[LATCH]] +; CHECK: [[LATCH]]: +; CHECK-NEXT: [[I_NEXT]] = add nuw nsw i32 [[I]], 1 +; CHECK-NEXT: [[BOUND:%.*]] = icmp ult i32 [[I_NEXT]], 128 +; CHECK-NEXT: br i1 [[BOUND]], label %[[LOOP]], label %[[EXIT]] +; CHECK: [[EXIT]]: +; CHECK-NEXT: [[RES:%.*]] = phi i32 [ [[I]], %[[LOOP]] ], [ [[I_NEXT]], %[[LATCH]] ] +; CHECK-NEXT: ret i32 [[RES]] +; +entry: + br label %loop + +loop: + %i = phi i32 [ 0, %entry ], [ %i.next, %latch ] + %f = phi float [ 0x3820000000000000, %entry ], [ %f.next, %latch ] + %f.next = fmul float %f, 5.000000e-01 + %scaled = fmul float %f.next, 0x47D0000000000000 + %fcmp = fcmp oeq float %scaled, 5.000000e-01 + br i1 %fcmp, label %exit, label %guard + +guard: + %scmp = icmp eq i32 %i, %stop + br i1 %scmp, label %exit, label %latch + +latch: + %i.next = add nuw nsw i32 %i, 1 + %bound = icmp ult i32 %i.next, 128 + br i1 %bound, label %loop, label %exit + +exit: + %res = phi i32 [ %i, %loop ], [ %i, %guard ], [ %i.next, %latch ] + ret i32 %res +} + +define i32 @denormal_fcmp_any(i32 %stop) #0 { +; CHECK-LABEL: define i32 @denormal_fcmp_any( +; CHECK-SAME: i32 [[STOP:%.*]]) #[[ATTR0]] { +; CHECK-NEXT: [[ENTRY:.*]]: +; CHECK-NEXT: br label %[[LOOP:.*]] +; CHECK: [[LOOP]]: +; CHECK-NEXT: [[I:%.*]] = phi i32 [ 0, %[[ENTRY]] ], [ [[I_NEXT:%.*]], %[[LATCH:.*]] ] +; CHECK-NEXT: [[I_NEXT]] = add nuw nsw i32 [[I]], 1 +; CHECK-NEXT: [[LATE:%.*]] = icmp ugt i32 [[I]], 2 +; CHECK-NEXT: [[F:%.*]] = select i1 [[LATE]], float 0x3800000000000000, float 0.000000e+00 +; CHECK-NEXT: [[FCMP:%.*]] = fcmp une float [[F]], 0.000000e+00 +; CHECK-NEXT: [[SCMP:%.*]] = icmp eq i32 [[I]], [[STOP]] +; CHECK-NEXT: [[OR_COND:%.*]] = or i1 [[FCMP]], [[SCMP]] +; CHECK-NEXT: br i1 [[OR_COND]], label %[[EXIT:.*]], label %[[LATCH]] +; CHECK: [[LATCH]]: +; CHECK-NEXT: [[BOUND:%.*]] = icmp ult i32 [[I_NEXT]], 128 +; CHECK-NEXT: br i1 [[BOUND]], label %[[LOOP]], label %[[EXIT]] +; CHECK: [[EXIT]]: +; CHECK-NEXT: [[RES:%.*]] = phi i32 [ [[I]], %[[LOOP]] ], [ [[I_NEXT]], %[[LATCH]] ] +; CHECK-NEXT: ret i32 [[RES]] +; +entry: + br label %loop + +loop: + %i = phi i32 [ 0, %entry ], [ %i.next, %latch ] + %n = phi i32 [ 0, %entry ], [ %n.next, %latch ] + %n.next = add nuw nsw i32 %n, 1 + %late = icmp ugt i32 %n, 2 + %f = select i1 %late, float 0x3800000000000000, float 0.000000e+00 + %fcmp = fcmp une float %f, 0.000000e+00 + br i1 %fcmp, label %exit, label %guard + +guard: + %scmp = icmp eq i32 %i, %stop + br i1 %scmp, label %exit, label %latch + +latch: + %i.next = add nuw nsw i32 %i, 1 + %bound = icmp ult i32 %i.next, 128 + br i1 %bound, label %loop, label %exit + +exit: + %res = phi i32 [ %i, %loop ], [ %i, %guard ], [ %i.next, %latch ] + ret i32 %res +} + +define i32 @denormal_vector_any(i32 %stop) #0 { +; CHECK-LABEL: define i32 @denormal_vector_any( +; CHECK-SAME: i32 [[STOP:%.*]]) #[[ATTR0]] { +; CHECK-NEXT: [[ENTRY:.*]]: +; CHECK-NEXT: br label %[[LOOP:.*]] +; CHECK: [[LOOP]]: +; CHECK-NEXT: [[I:%.*]] = phi i32 [ 0, %[[ENTRY]] ], [ [[I_NEXT:%.*]], %[[LATCH:.*]] ] +; CHECK-NEXT: [[F:%.*]] = phi <2 x float> [ , %[[ENTRY]] ], [ [[F_NEXT:%.*]], %[[LATCH]] ] +; CHECK-NEXT: [[F_NEXT]] = fmul <2 x float> [[F]], +; CHECK-NEXT: [[SCALEDV:%.*]] = fmul <2 x float> [[F_NEXT]], +; CHECK-NEXT: [[BITS:%.*]] = bitcast <2 x float> [[SCALEDV]] to i64 +; CHECK-NEXT: [[FCMP:%.*]] = icmp eq i64 [[BITS]], 1056964608 +; CHECK-NEXT: [[SCMP:%.*]] = icmp eq i32 [[I]], [[STOP]] +; CHECK-NEXT: [[OR_COND:%.*]] = or i1 [[FCMP]], [[SCMP]] +; CHECK-NEXT: br i1 [[OR_COND]], label %[[EXIT:.*]], label %[[LATCH]] +; CHECK: [[LATCH]]: +; CHECK-NEXT: [[I_NEXT]] = add nuw nsw i32 [[I]], 1 +; CHECK-NEXT: [[BOUND:%.*]] = icmp ult i32 [[I_NEXT]], 128 +; CHECK-NEXT: br i1 [[BOUND]], label %[[LOOP]], label %[[EXIT]] +; CHECK: [[EXIT]]: +; CHECK-NEXT: [[RES:%.*]] = phi i32 [ [[I]], %[[LOOP]] ], [ [[I_NEXT]], %[[LATCH]] ] +; CHECK-NEXT: ret i32 [[RES]] +; +entry: + br label %loop + +loop: + %i = phi i32 [ 0, %entry ], [ %i.next, %latch ] + %f = phi <2 x float> [ , %entry ], [ %f.next, %latch ] + %f.next = fmul <2 x float> %f, + %scaledv = fmul <2 x float> %f.next, + %bits = bitcast <2 x float> %scaledv to i64 + %fcmp = icmp eq i64 %bits, 1056964608 + br i1 %fcmp, label %exit, label %guard + +guard: + %scmp = icmp eq i32 %i, %stop + br i1 %scmp, label %exit, label %latch + +latch: + %i.next = add nuw nsw i32 %i, 1 + %bound = icmp ult i32 %i.next, 128 + br i1 %bound, label %loop, label %exit + +exit: + %res = phi i32 [ %i, %loop ], [ %i, %guard ], [ %i.next, %latch ] + ret i32 %res +} + +define i32 @denormal_fpext_any(i32 %stop) #0 { +; CHECK-LABEL: define i32 @denormal_fpext_any( +; CHECK-SAME: i32 [[STOP:%.*]]) #[[ATTR0]] { +; CHECK-NEXT: [[ENTRY:.*]]: +; CHECK-NEXT: br label %[[LOOP:.*]] +; CHECK: [[LOOP]]: +; CHECK-NEXT: [[I:%.*]] = phi i32 [ 0, %[[ENTRY]] ], [ [[I_NEXT:%.*]], %[[LATCH:.*]] ] +; CHECK-NEXT: [[I_NEXT]] = add nuw nsw i32 [[I]], 1 +; CHECK-NEXT: [[LATE:%.*]] = icmp ugt i32 [[I]], 2 +; CHECK-NEXT: [[F:%.*]] = select i1 [[LATE]], float 0x3800000000000000, float 0.000000e+00 +; CHECK-NEXT: [[D:%.*]] = fpext float [[F]] to double +; CHECK-NEXT: [[FCMP:%.*]] = fcmp une double [[D]], 0.000000e+00 +; CHECK-NEXT: [[SCMP:%.*]] = icmp eq i32 [[I]], [[STOP]] +; CHECK-NEXT: [[OR_COND:%.*]] = or i1 [[FCMP]], [[SCMP]] +; CHECK-NEXT: br i1 [[OR_COND]], label %[[EXIT:.*]], label %[[LATCH]] +; CHECK: [[LATCH]]: +; CHECK-NEXT: [[BOUND:%.*]] = icmp ult i32 [[I_NEXT]], 128 +; CHECK-NEXT: br i1 [[BOUND]], label %[[LOOP]], label %[[EXIT]] +; CHECK: [[EXIT]]: +; CHECK-NEXT: [[RES:%.*]] = phi i32 [ [[I]], %[[LOOP]] ], [ [[I_NEXT]], %[[LATCH]] ] +; CHECK-NEXT: ret i32 [[RES]] +; +entry: + br label %loop + +loop: + %i = phi i32 [ 0, %entry ], [ %i.next, %latch ] + %n = phi i32 [ 0, %entry ], [ %n.next, %latch ] + %n.next = add nuw nsw i32 %n, 1 + %late = icmp ugt i32 %n, 2 + %f = select i1 %late, float 0x3800000000000000, float 0.000000e+00 + %d = fpext float %f to double + %fcmp = fcmp une double %d, 0.000000e+00 + br i1 %fcmp, label %exit, label %guard + +guard: + %scmp = icmp eq i32 %i, %stop + br i1 %scmp, label %exit, label %latch + +latch: + %i.next = add nuw nsw i32 %i, 1 + %bound = icmp ult i32 %i.next, 128 + br i1 %bound, label %loop, label %exit + +exit: + %res = phi i32 [ %i, %loop ], [ %i, %guard ], [ %i.next, %latch ] + ret i32 %res +} + +define i32 @denormal_fptrunc_any(i32 %stop) #0 { +; CHECK-LABEL: define i32 @denormal_fptrunc_any( +; CHECK-SAME: i32 [[STOP:%.*]]) #[[ATTR0]] { +; CHECK-NEXT: [[ENTRY:.*]]: +; CHECK-NEXT: br label %[[LOOP:.*]] +; CHECK: [[LOOP]]: +; CHECK-NEXT: [[I:%.*]] = phi i32 [ 0, %[[ENTRY]] ], [ [[I_NEXT:%.*]], %[[LATCH:.*]] ] +; CHECK-NEXT: [[I_NEXT]] = add nuw nsw i32 [[I]], 1 +; CHECK-NEXT: [[LATE:%.*]] = icmp ugt i32 [[I]], 2 +; CHECK-NEXT: [[D:%.*]] = select i1 [[LATE]], double 0x3730000000000000, double 0.000000e+00 +; CHECK-NEXT: [[F:%.*]] = fptrunc double [[D]] to float +; CHECK-NEXT: [[BITS:%.*]] = bitcast float [[F]] to i32 +; CHECK-NEXT: [[FCMP:%.*]] = icmp ne i32 [[BITS]], 0 +; CHECK-NEXT: [[SCMP:%.*]] = icmp eq i32 [[I]], [[STOP]] +; CHECK-NEXT: [[OR_COND:%.*]] = or i1 [[FCMP]], [[SCMP]] +; CHECK-NEXT: br i1 [[OR_COND]], label %[[EXIT:.*]], label %[[LATCH]] +; CHECK: [[LATCH]]: +; CHECK-NEXT: [[BOUND:%.*]] = icmp ult i32 [[I_NEXT]], 128 +; CHECK-NEXT: br i1 [[BOUND]], label %[[LOOP]], label %[[EXIT]] +; CHECK: [[EXIT]]: +; CHECK-NEXT: [[RES:%.*]] = phi i32 [ [[I]], %[[LOOP]] ], [ [[I_NEXT]], %[[LATCH]] ] +; CHECK-NEXT: ret i32 [[RES]] +; +entry: + br label %loop + +loop: + %i = phi i32 [ 0, %entry ], [ %i.next, %latch ] + %n = phi i32 [ 0, %entry ], [ %n.next, %latch ] + %n.next = add nuw nsw i32 %n, 1 + %late = icmp ugt i32 %n, 2 + %d = select i1 %late, double 0x3730000000000000, double 0.000000e+00 + %f = fptrunc double %d to float + %bits = bitcast float %f to i32 + %fcmp = icmp ne i32 %bits, 0 + br i1 %fcmp, label %exit, label %guard + +guard: + %scmp = icmp eq i32 %i, %stop + br i1 %scmp, label %exit, label %latch + +latch: + %i.next = add nuw nsw i32 %i, 1 + %bound = icmp ult i32 %i.next, 128 + br i1 %bound, label %loop, label %exit + +exit: + %res = phi i32 [ %i, %loop ], [ %i, %guard ], [ %i.next, %latch ] + ret i32 %res +} + +define i32 @denormal_fmul_preserve(i32 %stop) #1 { +; CHECK-LABEL: define i32 @denormal_fmul_preserve( +; CHECK-SAME: i32 [[STOP:%.*]]) #[[ATTR1:[0-9]+]] { +; CHECK-NEXT: [[ENTRY:.*]]: +; CHECK-NEXT: br label %[[LOOP:.*]] +; CHECK: [[LOOP]]: +; CHECK-NEXT: [[I:%.*]] = phi i32 [ 0, %[[ENTRY]] ], [ [[I_NEXT:%.*]], %[[LATCH:.*]] ] +; CHECK-NEXT: [[F:%.*]] = phi float [ 0x3820000000000000, %[[ENTRY]] ], [ [[F_NEXT:%.*]], %[[LATCH]] ] +; CHECK-NEXT: [[F_NEXT]] = fmul float [[F]], 5.000000e-01 +; CHECK-NEXT: [[SCALED:%.*]] = fmul float [[F_NEXT]], 0x47D0000000000000 +; CHECK-NEXT: [[FCMP:%.*]] = fcmp oeq float [[SCALED]], 5.000000e-01 +; CHECK-NEXT: [[SCMP:%.*]] = icmp eq i32 [[I]], [[STOP]] +; CHECK-NEXT: [[OR_COND:%.*]] = or i1 [[FCMP]], [[SCMP]] +; CHECK-NEXT: br i1 [[OR_COND]], label %[[EXIT:.*]], label %[[LATCH]] +; CHECK: [[LATCH]]: +; CHECK-NEXT: [[I_NEXT]] = add nuw nsw i32 [[I]], 1 +; CHECK-NEXT: br i1 true, label %[[LOOP]], label %[[EXIT]] +; CHECK: [[EXIT]]: +; CHECK-NEXT: [[RES:%.*]] = phi i32 [ [[I]], %[[LOOP]] ], [ [[I_NEXT]], %[[LATCH]] ] +; CHECK-NEXT: ret i32 [[RES]] +; +entry: + br label %loop + +loop: + %i = phi i32 [ 0, %entry ], [ %i.next, %latch ] + %f = phi float [ 0x3820000000000000, %entry ], [ %f.next, %latch ] + %f.next = fmul float %f, 5.000000e-01 + %scaled = fmul float %f.next, 0x47D0000000000000 + %fcmp = fcmp oeq float %scaled, 5.000000e-01 + br i1 %fcmp, label %exit, label %guard + +guard: + %scmp = icmp eq i32 %i, %stop + br i1 %scmp, label %exit, label %latch + +latch: + %i.next = add nuw nsw i32 %i, 1 + %bound = icmp ult i32 %i.next, 128 + br i1 %bound, label %loop, label %exit + +exit: + %res = phi i32 [ %i, %loop ], [ %i, %guard ], [ %i.next, %latch ] + ret i32 %res +} + +attributes #0 = { "fp32-denorm-mode"="any" } +attributes #1 = { "fp32-denorm-mode"="preserve" }