2015-07-10 14:55:44 +08:00
|
|
|
; RUN: opt -instcombine -S < %s | FileCheck %s
|
|
|
|
|
|
|
|
target datalayout = "e-m:e-p:64:64:64-i64:64-f80:128-n8:16:32:64-S128"
|
|
|
|
|
|
|
|
; CHECK-LABEL: @test_load_load_combine_metadata(
|
2015-07-11 06:30:17 +08:00
|
|
|
; Check that range and AA metadata is combined
|
2015-07-10 14:55:44 +08:00
|
|
|
; CHECK: %[[V:.*]] = load i32, i32* %0
|
|
|
|
; CHECK-SAME: !tbaa !{{[0-9]+}}
|
|
|
|
; CHECK-SAME: !range ![[RANGE:[0-9]+]]
|
|
|
|
; CHECK: store i32 %[[V]], i32* %1
|
|
|
|
; CHECK: store i32 %[[V]], i32* %2
|
|
|
|
define void @test_load_load_combine_metadata(i32*, i32*, i32*) {
|
|
|
|
%a = load i32, i32* %0, !tbaa !8, !range !0, !alias.scope !5, !noalias !6
|
2015-07-11 06:30:17 +08:00
|
|
|
%b = load i32, i32* %0, !tbaa !8, !range !1
|
2015-07-10 14:55:44 +08:00
|
|
|
store i32 %a, i32* %1
|
|
|
|
store i32 %b, i32* %2
|
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
Handle non-constant shifts in computeKnownBits, and use computeKnownBits for constant folding in InstCombine/Simplify
First, the motivation: LLVM currently does not realize that:
((2072 >> (L == 0)) >> 7) & 1 == 0
where L is some arbitrary value. Whether you right-shift 2072 by 7 or by 8, the
lowest-order bit is always zero. There are obviously several ways to go about
fixing this, but the generic solution pursued in this patch is to teach
computeKnownBits something about shifts by a non-constant amount. Previously,
we would give up completely on these. Instead, in cases where we know something
about the low-order bits of the shift-amount operand, we can combine (and
together) the associated restrictions for all shift amounts consistent with
that knowledge. As a further generalization, I refactored all of the logic for
all three kinds of shifts to have this capability. This works well in the above
case, for example, because the dynamic shift amount can only be 0 or 1, and
thus we can say a lot about the known bits of the result.
This brings us to the second part of this change: Even when we know all of the
bits of a value via computeKnownBits, nothing used to constant-fold the result.
This introduces the necessary code into InstCombine and InstSimplify. I've
added it into both because:
1. InstCombine won't automatically pick up the associated logic in
InstSimplify (InstCombine uses InstSimplify, but not via the API that
passes in the original instruction).
2. Putting the logic in InstCombine allows the resulting simplifications to become
part of the iterative worklist
3. Putting the logic in InstSimplify allows the resulting simplifications to be
used by everywhere else that calls SimplifyInstruction (inlining, unrolling,
and many others).
And this requires a small change to our definition of an ephemeral value so
that we don't break the rest case from r246696 (where the icmp feeding the
@llvm.assume, is also feeding a br). Under the old definition, the icmp would
not be considered ephemeral (because it is used by the br), but this causes the
assume to remove itself (in addition to simplifying the branch structure), and
it seems more-useful to prevent that from happening.
llvm-svn: 251146
2015-10-24 04:37:08 +08:00
|
|
|
; CHECK: ![[RANGE]] = !{i32 0, i32 5, i32 7, i32 9}
|
|
|
|
!0 = !{ i32 0, i32 5 }
|
|
|
|
!1 = !{ i32 7, i32 9 }
|
2015-07-10 14:55:44 +08:00
|
|
|
!2 = !{!2}
|
|
|
|
!3 = !{!3, !2}
|
|
|
|
!4 = !{!4, !2}
|
|
|
|
!5 = !{!3}
|
|
|
|
!6 = !{!4}
|
|
|
|
!7 = !{ !"tbaa root" }
|
[Verifier] Add verification for TBAA metadata
Summary:
This change adds some verification in the IR verifier around struct path
TBAA metadata.
Other than some basic sanity checks (e.g. we get constant integers where
we expect constant integers), this checks:
- That by the time an struct access tuple `(base-type, offset)` is
"reduced" to a scalar base type, the offset is `0`. For instance, in
C++ you can't start from, say `("struct-a", 16)`, and end up with
`("int", 4)` -- by the time the base type is `"int"`, the offset
better be zero. In particular, a variant of this invariant is needed
for `llvm::getMostGenericTBAA` to be correct.
- That there are no cycles in a struct path.
- That struct type nodes have their offsets listed in an ascending
order.
- That when generating the struct access path, you eventually reach the
access type listed in the tbaa tag node.
Reviewers: dexonsmith, chandlerc, reames, mehdi_amini, manmanren
Subscribers: mcrosier, llvm-commits
Differential Revision: https://reviews.llvm.org/D26438
llvm-svn: 289402
2016-12-12 04:07:15 +08:00
|
|
|
!8 = !{ !9, !9, i64 0 }
|
|
|
|
!9 = !{ !"scalar type", !7}
|