Skip to content

Commit 2df25a4

Browse files
authored
Invalidate range metadata when folding bitcast into load (#133095)
1 parent 9438694 commit 2df25a4

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15964,6 +15964,15 @@ SDValue DAGCombiner::visitBITCAST(SDNode *N) {
1596415964

1596515965
if (TLI.isLoadBitCastBeneficial(N0.getValueType(), VT, DAG,
1596615966
*LN0->getMemOperand())) {
15967+
// If the range metadata type does not match the new memory
15968+
// operation type, remove the range metadata.
15969+
if (const MDNode *MD = LN0->getRanges()) {
15970+
ConstantInt *Lower = mdconst::extract<ConstantInt>(MD->getOperand(0));
15971+
if (Lower->getBitWidth() != VT.getScalarSizeInBits() ||
15972+
!VT.isInteger()) {
15973+
LN0->getMemOperand()->clearRanges();
15974+
}
15975+
}
1596715976
SDValue Load =
1596815977
DAG.getLoad(VT, SDLoc(N), LN0->getChain(), LN0->getBasePtr(),
1596915978
LN0->getMemOperand());
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5
2+
; RUN: llc -mtriple=x86_64-apple-macosx10.12.0 < %s | FileCheck %s
3+
4+
; Ensure that when a bitcast is folded into a load, range metadata is invalidated
5+
; if it does not match the new type.
6+
7+
define i1 @fold_bitcast_range_metadata(ptr %valptr) {
8+
; CHECK-LABEL: fold_bitcast_range_metadata:
9+
; CHECK: ## %bb.0: ## %start
10+
; CHECK-NEXT: movdqa (%rdi), %xmm0
11+
; CHECK-NEXT: pcmpeqb {{\.?LCPI[0-9]+_[0-9]+}}(%rip), %xmm0
12+
; CHECK-NEXT: pmovmskb %xmm0, %eax
13+
; CHECK-NEXT: cmpl $65535, %eax ## imm = 0xFFFF
14+
; CHECK-NEXT: sete %al
15+
; CHECK-NEXT: retq
16+
start:
17+
%val = load i128, ptr %valptr, align 16, !range !0, !noundef !1
18+
%bool = icmp eq i128 %val, 1
19+
ret i1 %bool
20+
}
21+
22+
!0 = !{i128 0, i128 3}
23+
!1 = !{}

0 commit comments

Comments
 (0)