<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<span style="font-family: "segoe ui", "segoe ui web (west european)", "segoe ui", -apple-system, blinkmacsystemfont, roboto, "helvetica neue", sans-serif; font-size: 11pt; color: rgb(50, 49, 48); background-color: rgba(0, 0, 0, 0);">Hello Johannes,</span></div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<span id="SmartSuggestionsKeyword664423" title="Search for suggestions" class="_1oldRGGSrcSFxv9Y7vQEqL" style="font-family: "segoe ui", "segoe ui web (west european)", "segoe ui", -apple-system, blinkmacsystemfont, roboto, "helvetica neue", sans-serif; font-size: 11pt; color: rgb(50, 49, 48); background-color: rgba(0, 0, 0, 0);">Thanks</span><span title="Search for suggestions" class="_1aFK1bl8nu9HzQ8EPIECQr"><span style="font-family: "segoe ui", "segoe ui web (west european)", "segoe ui", -apple-system, blinkmacsystemfont, roboto, "helvetica neue", sans-serif; font-size: 11pt; color: rgb(50, 49, 48); background-color: rgba(0, 0, 0, 0);"> for
 your suggestion! The ScalarEvolution analysis is very helpful.</span></div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<span style="font-family: "segoe ui", "segoe ui web (west european)", "segoe ui", -apple-system, blinkmacsystemfont, roboto, "helvetica neue", sans-serif; font-size: 11pt; color: rgb(50, 49, 48); background-color: rgba(0, 0, 0, 0);">I had a follow-up question.
 It would be great if you can take a look. </span></div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<span style="color: rgb(50, 49, 48); font-family: "Segoe UI", "Segoe UI Web (West European)", "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, "Helvetica Neue", sans-serif; font-size: 14.6667px; background-color: rgb(255, 255, 255); display: inline !important"><span> </span>%11
 = load float*, float** %a.addr, align 8, !dbg !954</span></div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<span style="color: rgb(50, 49, 48); font-family: "Segoe UI", "Segoe UI Web (West European)", "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, "Helvetica Neue", sans-serif; font-size: 14.6667px; background-color: rgb(255, 255, 255); display: inline !important"> %12
 = load i32, i32* %i, align 4, !dbg !955</span><br style="color: rgb(50, 49, 48); font-family: "Segoe UI", "Segoe UI Web (West European)", "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, "Helvetica Neue", sans-serif; font-size: 14.6667px; background-color: rgb(255, 255, 255)">
<span style="color: rgb(50, 49, 48); font-family: "Segoe UI", "Segoe UI Web (West European)", "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, "Helvetica Neue", sans-serif; font-size: 14.6667px; background-color: rgb(255, 255, 255); display: inline !important"> %sub
 = sub nsw i32 %12, 1, !dbg !956</span><br style="color: rgb(50, 49, 48); font-family: "Segoe UI", "Segoe UI Web (West European)", "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, "Helvetica Neue", sans-serif; font-size: 14.6667px; background-color: rgb(255, 255, 255)">
<span style="color: rgb(50, 49, 48); font-family: "Segoe UI", "Segoe UI Web (West European)", "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, "Helvetica Neue", sans-serif; font-size: 14.6667px; background-color: rgb(255, 255, 255); display: inline !important"> %idxprom7
 = sext i32 %sub to i64, !dbg !954</span><br style="color: rgb(50, 49, 48); font-family: "Segoe UI", "Segoe UI Web (West European)", "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, "Helvetica Neue", sans-serif; font-size: 14.6667px; background-color: rgb(255, 255, 255)">
<span style="color: rgb(50, 49, 48); font-family: "Segoe UI", "Segoe UI Web (West European)", "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, "Helvetica Neue", sans-serif; font-size: 14.6667px; background-color: rgb(255, 255, 255); display: inline !important"> %arrayidx8
 = getelementptr inbounds float, float* %11, i64 %idxprom7, !dbg !954</span><br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<span style="color: rgb(50, 49, 48); font-family: "Segoe UI", "Segoe UI Web (West European)", "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, "Helvetica Neue", sans-serif; font-size: 14.6667px; background-color: rgb(255, 255, 255); display: inline !important"><br>
</span></div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<span style="color: rgb(50, 49, 48); font-family: "Segoe UI", "Segoe UI Web (West European)", "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, "Helvetica Neue", sans-serif; font-size: 14.6667px; background-color: rgb(255, 255, 255); display: inline !important">For
 the above code, the result for %idxprom7 is: (-1 + (sext i32 %12 to i64))<nsw>. Just wondering if you have any suggestion that I can replace <span style="font-family: "Segoe UI", "Segoe UI Web (West European)", "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, "Helvetica Neue", sans-serif; background-color: rgb(255, 255, 255); display: inline !important">(sext
 i32 %12 to i64) with symbol %i</span></span></div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<span style="color: rgb(50, 49, 48); font-family: "Segoe UI", "Segoe UI Web (West European)", "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, "Helvetica Neue", sans-serif; font-size: 14.6667px; background-color: rgb(255, 255, 255); display: inline !important"><span style="font-family: "Segoe UI", "Segoe UI Web (West European)", "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, "Helvetica Neue", sans-serif; background-color: rgb(255, 255, 255); display: inline !important"><br>
</span></span></div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<span style="color: rgb(50, 49, 48); font-family: "Segoe UI", "Segoe UI Web (West European)", "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, "Helvetica Neue", sans-serif; font-size: 14.6667px; background-color: rgb(255, 255, 255); display: inline !important"><span style="font-family: "Segoe UI", "Segoe UI Web (West European)", "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, "Helvetica Neue", sans-serif; background-color: rgb(255, 255, 255); display: inline !important"><br>
</span></span></div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<span style="color: rgb(50, 49, 48); font-family: "Segoe UI", "Segoe UI Web (West European)", "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, "Helvetica Neue", sans-serif; font-size: 14.6667px; background-color: rgb(255, 255, 255); display: inline !important"><span style="font-family: "Segoe UI", "Segoe UI Web (West European)", "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, "Helvetica Neue", sans-serif; background-color: rgb(255, 255, 255); display: inline !important">Thanks,</span></span></div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<span style="color: rgb(50, 49, 48); font-family: "Segoe UI", "Segoe UI Web (West European)", "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, "Helvetica Neue", sans-serif; font-size: 14.6667px; background-color: rgb(255, 255, 255); display: inline !important"><span style="font-family: "Segoe UI", "Segoe UI Web (West European)", "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, "Helvetica Neue", sans-serif; background-color: rgb(255, 255, 255); display: inline !important">Michael</span></span></div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0);">
<br>
<hr tabindex="-1" style="display:inline-block; width:98%;">
<b>From:</b> Johannes Doerfert<br>
<b>Sent:</b> Tuesday, February 18, 2020 5:34 PM<br>
<b>To:</b> Michael Meng<br>
<b>Cc:</b> Michael Kruse; via llvm-dev<br>
<b>Subject:</b> Re: [llvm-dev] Differentiate array access at IR level
<div><br>
</div>
</div>
<div class="BodyFragment"><font size="2"><span style="font-size:11pt;">
<div class="PlainText">Hi Michael,<br>
<br>
You should run mem2reg on your code, e.g. use the "create_ll.sh" script<br>
in `polly/test/create_ll.sh` to transform little C files to '.ll' files.<br>
<br>
The solution I would go for looks something like this, assuming this is<br>
in a pass in which LoopInfo is available as LI and ScalarEvolution as SE.<br>
<br>
```<br>
  DenseMap<std::pair<Loop *, const SCEV *>, unsigned> Reads, Writes;<br>
<br>
  void dealWithLoopAndSubLoops(Loop &L) {<br>
    for (BasicBlock *BB : L.blocks()) {<br>
      for (Instruction &I : *BB) {<br>
        if (LoadInst *Load = dyn_cast<LoadInst>(&I)) {<br>
          Reads[{&L, SE->getSCEVAtScope(Load->getPointerOperand())}] += 1<br>
        } else if (StoreInst *Store = dyn_cast<StoreInst>(&I)) {<br>
          Writes[{&L, SE->getSCEVAtScope(Store->getPointerOperand())}] += 1<br>
        }<br>
      }<br>
    }<br>
    for (Loop *SubL : L)<br>
      dealWithLoopAndSubLoops(*SubL);<br>
  }<br>
<br>
  void run(...) {<br>
    for (Loop *L : *LI)<br>
      dealWithLoopAndSubLoops(*L);<br>
<br>
    errs() << "Reads:\n";<br>
    for (auto &It : Reads) {<br>
      errs() << " - Location: " << *It.first.second << " Loop: " <<<br>
      It.first.first->getName() << " Access count: " << It.second << "\n";<br>
    }<br>
    errs() << "Writes:\n";<br>
    for (auto &It : Writes) {<br>
      errs() << " - Location: " << *It.first.second << " Loop: " <<<br>
      It.first.first->getName() << " Access count: " << It.second << "\n";<br>
    }<br>
  }<br>
```<br>
<br>
Note that this is not tested in any way.<br>
<br>
Hope this helps.<br>
<br>
<br>
Cheers,<br>
  Johannes<br>
<br>
On 02/19, Michael Meng via llvm-dev wrote:<br>
> Hi Michael,<br>
> <br>
> Thanks for your reply!<br>
> <br>
> Since I want to collect the counts of unique array access to array elements in one iteration, so I consider a[i] and a[i - 1] as two accesses to different array elements. Would it be possible to get the notion of "i - 1" at IR level.<br>
> <br>
> The IR looks like:<br>
> <br>
> %11 = load float*, float** %a.addr, align 8, !dbg !954<br>
> %12 = load i32, i32* %i, align 4, !dbg !955<br>
> %sub = sub nsw i32 %12, 1, !dbg !956<br>
> %idxprom7 = sext i32 %sub to i64, !dbg !954<br>
> %arrayidx8 = getelementptr inbounds float, float* %11, i64 %idxprom7, !dbg !954<br>
> <br>
> Working the the source level might be easier, but I wonder if it is possible to know idxprom7 -> i - 1 with IR<br>
> <br>
> <br>
> Thanks again!<br>
> Michael<br>
> ________________________________<br>
> From: Michael Kruse <llvmdev@meinersbur.de><br>
> Sent: Tuesday, February 18, 2020 9:26 AM<br>
> To: Michael Meng <overrainbow2013@hotmail.com><br>
> Cc: via llvm-dev <llvm-dev@lists.llvm.org><br>
> Subject: Re: [llvm-dev] Differentiate array access at IR level<br>
> <br>
> Note that a[i] are a[i-1] are accessing the same memory addresses,<br>
> just not in the same loop iteration. You may want to look into<br>
> DependenceInfo.<br>
> <br>
> Michael<br>
> <br>
> Am Mo., 17. Feb. 2020 um 00:04 Uhr schrieb Michael Meng via llvm-dev<br>
> <llvm-dev@lists.llvm.org>:<br>
> ><br>
> > Hi LLVM community,<br>
> ><br>
> > I am trying to differentiate access to different array elements, for example:<br>
> ><br>
> > for (int i = 1; i < 10; i++) {<br>
> ><br>
> >     a[i] = a[i] + 10;<br>
> ><br>
> >      b[i] = a[i - 1]  * 2;<br>
> ><br>
> > }<br>
> ><br>
> > If it is possible to tell it loads/stores 3 different array elements: a[i], b[i] and a[i - 1] at IR level?<br>
> ><br>
> ><br>
> > Thanks for your time in advance!<br>
> ><br>
> ><br>
> > Best,<br>
> > Michael<br>
> > _______________________________________________<br>
> > LLVM Developers mailing list<br>
> > llvm-dev@lists.llvm.org<br>
> > <a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" target="_blank" rel="noopener noreferrer" data-auth="NotApplicable">
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
<br>
> _______________________________________________<br>
> LLVM Developers mailing list<br>
> llvm-dev@lists.llvm.org<br>
> <a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" target="_blank" rel="noopener noreferrer" data-auth="NotApplicable">
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
<br>
<br>
-- <br>
<br>
Johannes Doerfert<br>
Researcher<br>
<br>
Argonne National Laboratory<br>
Lemont, IL 60439, USA<br>
<br>
jdoerfert@anl.gov<br>
</div>
</span></font></div>
</span>
</body>
</html>