llvm.org GIT mirror llvm / 94f2c23
[indvars] Fix bugs in floating point IV range checks noticed by inspection. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@139574 91177308-0d34-0410-b5e6-96231b3b80d8 Andrew Trick 8 years ago
2 changed file(s) with 13 addition(s) and 13 deletion(s). Raw diff Collapse all Expand all
350350 // Positive and negative strides have different safety conditions.
351351 if (IncValue > 0) {
352352 // If we have a positive stride, we require the init to be less than the
353 // exit value and an equality or less than comparison.
354 if (InitValue >= ExitValue ||
355 NewPred == CmpInst::ICMP_SGT || NewPred == CmpInst::ICMP_SGE)
353 // exit value.
354 if (InitValue >= ExitValue)
356355 return;
357356
358357 uint32_t Range = uint32_t(ExitValue-InitValue);
359 if (NewPred == CmpInst::ICMP_SLE) {
360 // Normalize SLE -> SLT, check for infinite loop.
358 // Check for infinite loop, either:
359 // while (i <= Exit) or until (i > Exit)
360 if (NewPred == CmpInst::ICMP_SLE || NewPred == CmpInst::ICMP_SGT) {
361361 if (++Range == 0) return; // Range overflows.
362362 }
363363
377377
378378 } else {
379379 // If we have a negative stride, we require the init to be greater than the
380 // exit value and an equality or greater than comparison.
381 if (InitValue >= ExitValue ||
382 NewPred == CmpInst::ICMP_SLT || NewPred == CmpInst::ICMP_SLE)
380 // exit value.
381 if (InitValue <= ExitValue)
383382 return;
384383
385384 uint32_t Range = uint32_t(InitValue-ExitValue);
386 if (NewPred == CmpInst::ICMP_SGE) {
387 // Normalize SGE -> SGT, check for infinite loop.
385 // Check for infinite loop, either:
386 // while (i >= Exit) or until (i < Exit)
387 if (NewPred == CmpInst::ICMP_SGE || NewPred == CmpInst::ICMP_SLT) {
388388 if (++Range == 0) return; // Range overflows.
389389 }
390390
6666 return:
6767 ret void
6868 ; CHECK: @test4
69 ; CHECK: fcmp
69 ; CHECK-NOT: cmp
70 ; CHECK: br i1 false
7071 }
7172
7273 ; PR6761
8384
8485 exit:
8586 ret void
86
87
8788 ; CHECK: @test5
8889 ; CHECK: icmp eq i32 {{.*}}, 10
8990 ; CHECK-NEXT: br i1
9091 }
91