Skip to content

Commit 2306f43

Browse files
committed
[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.
1 parent ed5fe64 commit 2306f43

File tree

1 file changed

+10
-16
lines changed

1 file changed

+10
-16
lines changed

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

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
;; if (a[i] > a[t])
5858
;; t = i;
5959
;; }
60-
;; return a[t];
60+
;; return t;
6161
;;}
6262
;;
6363
;;
@@ -177,30 +177,24 @@ for.body.preheader: ; preds = %entry
177177
%wide.trip.count = zext i32 %n to i64
178178
br label %for.body
179179

180-
for.cond.cleanup.loopexit: ; preds = %for.body
181-
%phitmp = sext i32 %i.0.t.0 to i64
182-
br label %for.cond.cleanup
183-
184-
for.cond.cleanup: ; preds = %for.cond.cleanup.loopexit, %entry
185-
%t.0.lcssa = phi i64 [ 0, %entry ], [ %phitmp, %for.cond.cleanup.loopexit ]
186-
%arrayidx5 = getelementptr inbounds i32, i32* %a, i64 %t.0.lcssa
187-
%0 = load i32, i32* %arrayidx5, align 4
188-
ret i32 %0
180+
for.cond.cleanup: ; preds = %for.body, %entry
181+
%t.0.lcssa = phi i32 [ 0, %entry ], [ %i.0.t.0, %for.body ]
182+
ret i32 %t.0.lcssa
189183

190184
for.body: ; preds = %for.body.preheader, %for.body
191185
%indvars.iv = phi i64 [ %indvars.iv.next, %for.body ], [ 1, %for.body.preheader ]
192186
%t.015 = phi i32 [ %i.0.t.0, %for.body ], [ 0, %for.body.preheader ]
193187
%arrayidx = getelementptr inbounds i32, i32* %a, i64 %indvars.iv
194-
%1 = load i32, i32* %arrayidx, align 4
188+
%0 = load i32, i32* %arrayidx, align 4
195189
%idxprom1 = sext i32 %t.015 to i64
196190
%arrayidx2 = getelementptr inbounds i32, i32* %a, i64 %idxprom1
197-
%2 = load i32, i32* %arrayidx2, align 4
198-
%cmp3 = icmp sgt i32 %1, %2
199-
%3 = trunc i64 %indvars.iv to i32
200-
%i.0.t.0 = select i1 %cmp3, i32 %3, i32 %t.015
191+
%1 = load i32, i32* %arrayidx2, align 4
192+
%cmp3 = icmp sgt i32 %0, %1
193+
%2 = trunc i64 %indvars.iv to i32
194+
%i.0.t.0 = select i1 %cmp3, i32 %2, i32 %t.015
201195
%indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
202196
%exitcond = icmp eq i64 %indvars.iv.next, %wide.trip.count
203-
br i1 %exitcond, label %for.cond.cleanup.loopexit, label %for.body
197+
br i1 %exitcond, label %for.cond.cleanup, label %for.body
204198
}
205199

206200
; CHECK-LABEL: MaxValue

0 commit comments

Comments
 (0)