This is an archive of the discontinued LLVM Phabricator instance.

[BUG] "Rotate Loop" pass kills "llvm.vectorizer.enable" metadata
ClosedPublic

Authored by zinovy.nis on Apr 10 2014, 8:17 AM.

Details

Summary

Hi.

I faced that "llvm.vectorizer.enable" metadata used by Loop Vectorizer and set by OpenMP pragmas are killed after the "Rotate Loop" pass. The branch containing the metadata is replaced with another one, but without any metadata.
So "Loop Vectorizer" won't force vectorization of this loop.

I fixed it by storing the loop metadata in the begining of LoopRotate pass and then restoring it just before return from the pass.
I also added a test for it. It checks that LoopVectorize sees "llvm.vectorizer.enable" metadata.

Diff Detail

Event Timeline

nadav added a comment.Apr 10 2014, 9:06 AM

Looking good!

atrick accepted this revision.Apr 11 2014, 9:21 AM

LGTM

What if the call to simplifyLoopLatch (at line 93 in lib/Transforms/Scalar/LoopRotation.cpp) removes metadata and subsequent rotateLoop at line 97 will not do anything, here is a small testcase for this. Is it possible to restore metadata here in the same way?

; RUN: opt < %s -O2 -force-vector-unroll=2 -force-vector-width=4 -debug-only=loop-vectorize -stats -S 2>&1 | FileCheck %s

; CHECK: LV: Loop hints: force=enabled

target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

define i32 @foo(i32 %a) #0 {
entry:
  br label %loop_cond

loop_cond:                                        ; preds = %loop_inc, %entry
  %indx = phi i32 [ 1, %entry ], [ %inc, %loop_inc ]
  %cmp = icmp ne i32 %indx, %a
  br i1 %cmp, label %return, label %loop_inc

loop_inc:                                         ; preds = %loop_cond
  %inc = add i32 %indx, 1
  br label %loop_cond, !llvm.loop !1

return:                                           ; preds = %loop_cond
  ret i32 0
}

attributes #0 = { nounwind uwtable }

!1 = metadata !{metadata !1, metadata !2}
!2 = metadata !{metadata !"llvm.vectorizer.enable", i1 true}
zinovy.nis updated this revision to Unknown Object (????).Apr 14 2014, 5:50 AM

My new patch fixes the issue kindly pointed by Alexander M.

Please re-review it again.

Could you please commit this patch for me?

ABataev closed this revision.Apr 15 2014, 2:44 AM

Committed revision 206266.

Hi Zinovy,

I have a question about your test case. Did you manually add the