[llvm-dev] Finding LoadInsts that are not affected by external values.

Insu Yun via llvm-dev llvm-dev at lists.llvm.org
Wed Dec 4 17:31:01 PST 2019


Hi, all.
I am currently trying to find LoadInst, which are not dependent external
values (e.g., arguments or Global variable).

```
int f(int x) {
        for (int i = 0; i < 1000; i++) {
                x += x * i;
        }
        return x;
}
```

For example, in the above code,  `x` is from argument, and `i` is not.

```
define i32 @f(i32 %x) #0 {
entry:
  %x.addr = alloca i32, align 4
  %i = alloca i32, align 4
  store i32 %x, i32* %x.addr, align 4
  store i32 0, i32* %i, align 4
  br label %for.cond

for.cond:                                         ; preds = %for.inc, %entry
  %0 = load i32, i32* %i, align 4
  %cmp = icmp slt i32 %0, 1000
  br i1 %cmp, label %for.body, label %for.end

for.body:                                         ; preds = %for.cond
  %1 = load i32, i32* %x.addr, align 4
  %2 = load i32, i32* %i, align 4
  %mul = mul nsw i32 %1, %2
  %3 = load i32, i32* %x.addr, align 4
  %add = add nsw i32 %3, %mul
  store i32 %add, i32* %x.addr, align 4
  br label %for.inc

for.inc:                                          ; preds = %for.body
  %4 = load i32, i32* %i, align 4
  %inc = add nsw i32 %4, 1
  store i32 %inc, i32* %i, align 4
  br label %for.cond

for.end:                                          ; preds = %for.cond
  %5 = load i32, i32* %x.addr, align 4
  ret i32 %5
}
```

As I can see above, it needs to handle store and load.
I think I can do simple dataflow analysis to do that.
But I wonder whether there is a standard, mature way in LLVM.

```
// -fsanitize=dataflow
  store i16 %21, i16* %2
  store i32 %inc, i32* %i, align 4
```
I thought that this analysis should be implemented in DataFlowSanitizer.
But, it still propagates taint symbol to `i`.

Is there any standard way to do this?
Thank you.

Best,
Insu Yun.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20191204/9f7e9043/attachment.html>


More information about the llvm-dev mailing list