[llvm] 2306f43 - [X86] Update MaxIndex test in x86-cmov-converter.ll to return the index and not use the index to look up the array after the loop.

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Sat Jan 4 00:03:27 PST 2020


Author: Craig Topper
Date: 2020-01-03T23:59:54-08:00
New Revision: 2306f43ccb46627b92aa0bb48b96437984c50c01

URL: https://github.com/llvm/llvm-project/commit/2306f43ccb46627b92aa0bb48b96437984c50c01
DIFF: https://github.com/llvm/llvm-project/commit/2306f43ccb46627b92aa0bb48b96437984c50c01.diff

LOG: [X86] Update MaxIndex test in x86-cmov-converter.ll to return the index and not use the index to look up the array after the loop.

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.

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/llvm/test/CodeGen/X86/x86-cmov-converter.ll b/llvm/test/CodeGen/X86/x86-cmov-converter.ll
index d9a2f6b24f28..1f7565008c0f 100644
--- a/llvm/test/CodeGen/X86/x86-cmov-converter.ll
+++ b/llvm/test/CodeGen/X86/x86-cmov-converter.ll
@@ -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


        


More information about the llvm-commits mailing list