/// Unrolls this loop completely.
bool mlir::loopUnrollFull(ForStmt *forStmt) {
- Optional<uint64_t> tripCount = getConstantTripCount(*forStmt);
- if (tripCount.hasValue())
- return loopUnrollByFactor(forStmt, tripCount.getValue());
+ Optional<uint64_t> mayBeConstantTripCount = getConstantTripCount(*forStmt);
+ if (mayBeConstantTripCount.hasValue()) {
+ uint64_t tripCount = mayBeConstantTripCount.getValue();
+ if (tripCount == 1) {
+ return promoteIfSingleIteration(forStmt);
+ }
+ return loopUnrollByFactor(forStmt, tripCount);
+ }
return false;
}
}
return
}
+
+// CHECK-LABEL: mlfunc @loop_nest_unroll_full() {
+mlfunc @loop_nest_unroll_full() {
+ // CHECK-NEXT: %0 = "foo"() : () -> i32
+ // CHECK-NEXT: %1 = "bar"() : () -> i32
+ // CHECK-NEXT: return
+ for %i = 0 to 0 {
+ %x = "foo"() : () -> i32
+ %y = "bar"() : () -> i32
+ }
+ return
+} // CHECK }