Issue 134540
Summary Missed optimization when using `llvm.assume`, although scalar-evolution can use it to figure out the range.
Labels new issue
Assignees
Reporter GINN-Imp
    Missed optimization: `store i1 %0, ptr @a, align 1` --> `store i1 true, ptr @a, align 1`

```llvm
@a = external global i1
define i1 @src(ptr %G) {
BB:
  %L = load i1, ptr %G, align 1
 %0 = xor i1 %L, true
  store i1 %0, ptr @a, align 1
  call void @llvm.assume(i1 %0)
  ret i1 %0
}
```

clang-trunk -O3 generates:
```llvm
define noundef i1 @src(ptr readonly captures(none) %G) local_unnamed_addr #0 {
  %L = load i1, ptr %G, align 1
  %0 = xor i1 %L, true
  store i1 %0, ptr @a, align 1
  tail call void @llvm.assume(i1 %0)
 ret i1 true
}

```

We found that `scalar-evolution` looked like it could do some analysis with llvm.assume (it found that the value of `%L` was `false`), but the optimization was still missed:
```
Printing analysis 'Scalar Evolution Analysis' for function 'src':
Classifying expressions for: @src
  %L = load i1, ptr %G, align 1
  -->  %L U: [0,-1) S: [0,-1)
```

Godbolt: https://godbolt.org/z/bd9fEGe18
Alive2 proof: https://alive2.llvm.org/ce/z/AYhVHx
The reduced IR is derived from https://github.com/torvalds/linux/blob/master/mm/page_alloc.c
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to