llvm / llvm/llvm-project

[InstCombine] Sinking an instruction drops separate_storage assume bundles instead of moving the assume

Open
#223,008 0 comments 0 reactions 0 assignees View on GitHub
llvm:instcombine
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

Instcombine drops the assume when moving the pointer around. And I wonder if it could avoid doing that in some cases.

Unclear if it's legal to not drop the assume when moving it. but here at least domination wise I think it's legal to sink the assume wholesale.

```llvm
declare ptr @get_base(ptr) memory(none) nounwind willreturn
declare void @llvm.assume(i1)

define double @f(ptr %p, ptr %b, i1 %c) {
entry:
%a = call ptr @get_base(ptr %p)
call void @llvm.assume(i1 true) [ "separate_storage"(ptr %a, ptr %b) ]
br i1 %c, label %use, label %exit

use:
%v1 = load double, ptr %a
store double 0.0, ptr %b
%v2 = load double, ptr %a
%s = fadd double %v1, %v2
ret double %s

exit:
ret double 0.0
}
```

```
opt -passes=instcombine -S repro.ll
```

```llvm
define double @f(ptr %p, ptr %b, i1 %c) {
entry:
br i1 %c, label %use, label %exit

use: ; preds = %entry
%a = call ptr @get_base(ptr %p)
%v1 = load double, ptr %a, align 8
store double 0.000000e+00, ptr %b, align 8
%v2 = load double, ptr %a, align 8
%s = fadd double %v1, %v2
ret double %s

exit: ; preds = %entry
ret double 0.000000e+00
}
```

Contributor guide

Open the contributing guide

Research direction

Start with the InstCombine handling exercised by the provided repro.ll and run `opt -passes=instcombine -S repro.ll` to inspect how the `llvm.assume` with a `separate_storage` bundle is transformed. Determine whether the assume can be sunk with the moved pointer while preserving valid domination, and consider the work complete when the legal case retains or moves the assume instead of dropping it.

Written by the indexing model from the issue text.

Assessment

Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.