[X86] Update MaxIndex test in x86-cmov-converter.ll to return the index and not use...
authorCraig Topper <craig.topper@gmail.com>
Sat, 4 Jan 2020 07:58:43 +0000 (23:58 -0800)
committerCraig Topper <craig.topper@gmail.com>
Sat, 4 Jan 2020 07:59:54 +0000 (23:59 -0800)
This represents a more realistic version of the code being tested.
The cmov converter doesn't look at the code after the loop so
it doesn't matter for what's being tested.

But as noted in this twitter thread https://twitter.com/trav_downs/status/1213311159413161987
gcc can turn the previous MaxIndex code into the MaxValue code. So
returning the index makes it a distinct case.

llvm/test/CodeGen/X86/x86-cmov-converter.ll

index d9a2f6b..1f75650 100644 (file)
@@ -57,7 +57,7 @@
 ;;    if (a[i] > a[t])
 ;;      t = i;
 ;;  }
-;;  return a[t];
+;;  return t;
 ;;}
 ;;
 ;;
@@ -177,30 +177,24 @@ for.body.preheader:                               ; preds = %entry
   %wide.trip.count = zext i32 %n to i64
   br label %for.body
 
-for.cond.cleanup.loopexit:                        ; preds = %for.body
-  %phitmp = sext i32 %i.0.t.0 to i64
-  br label %for.cond.cleanup
-
-for.cond.cleanup:                                 ; preds = %for.cond.cleanup.loopexit, %entry
-  %t.0.lcssa = phi i64 [ 0, %entry ], [ %phitmp, %for.cond.cleanup.loopexit ]
-  %arrayidx5 = getelementptr inbounds i32, i32* %a, i64 %t.0.lcssa
-  %0 = load i32, i32* %arrayidx5, align 4
-  ret i32 %0
+for.cond.cleanup:                                 ; preds = %for.body, %entry
+  %t.0.lcssa = phi i32 [ 0, %entry ], [ %i.0.t.0, %for.body ]
+  ret i32 %t.0.lcssa
 
 for.body:                                         ; preds = %for.body.preheader, %for.body
   %indvars.iv = phi i64 [ %indvars.iv.next, %for.body ], [ 1, %for.body.preheader ]
   %t.015 = phi i32 [ %i.0.t.0, %for.body ], [ 0, %for.body.preheader ]
   %arrayidx = getelementptr inbounds i32, i32* %a, i64 %indvars.iv
-  %1 = load i32, i32* %arrayidx, align 4
+  %0 = load i32, i32* %arrayidx, align 4
   %idxprom1 = sext i32 %t.015 to i64
   %arrayidx2 = getelementptr inbounds i32, i32* %a, i64 %idxprom1
-  %2 = load i32, i32* %arrayidx2, align 4
-  %cmp3 = icmp sgt i32 %1, %2
-  %3 = trunc i64 %indvars.iv to i32
-  %i.0.t.0 = select i1 %cmp3, i32 %3, i32 %t.015
+  %1 = load i32, i32* %arrayidx2, align 4
+  %cmp3 = icmp sgt i32 %0, %1
+  %2 = trunc i64 %indvars.iv to i32
+  %i.0.t.0 = select i1 %cmp3, i32 %2, i32 %t.015
   %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
   %exitcond = icmp eq i64 %indvars.iv.next, %wide.trip.count
-  br i1 %exitcond, label %for.cond.cleanup.loopexit, label %for.body
+  br i1 %exitcond, label %for.cond.cleanup, label %for.body
 }
 
 ; CHECK-LABEL: MaxValue