llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
27.13k stars 11.11k forks source link

Failure to exploit assume to eliminate use of load #42503

Open preames opened 4 years ago

preames commented 4 years ago
Bugzilla Link 43158
Version trunk
OS Linux

Extended Description

Test case: define i32 @​test(i32 %p, i32 %v) { %load = load i32, i32 %p %c = icmp eq i32 %load, %v call void @​llvm.assume(i1 %c) ret i32 %load }

define i32 @​reverse(i32 %p, i32 %v) { %load = load i32, i32 %p %c = icmp eq i32 %load, %v call void @​llvm.assume(i1 %c) ret i32 %v }

declare void @​llvm.assume(i1)

Both of these examples are stable under O3; we really should be canonicalizing to one or the other. In this particular example, reverse is the better of the two, but a general heuristic requires more thought.

GVN's propagateEquality has a "prefer early valno" heuristic which appears reasonable. GVN has a separate constant replacement in operands heuristic which also seems reasonable. I suspect these two need to be unified into something of a broader scope.

preames commented 4 years ago

Fix out for review: https://reviews.llvm.org/D66977