Skip to content

Commit 215aca4

Browse files
authored
[GlobalISel] SBFX/UBFX does not create poison (#165675)
This adds G_SBFX/G_UBFX to the list of instructions that do not generate poison, to allowing freeze to be hoisted above one.
1 parent a6eac9e commit 215aca4

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

llvm/lib/CodeGen/GlobalISel/Utils.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1893,6 +1893,8 @@ static bool canCreateUndefOrPoison(Register Reg, const MachineRegisterInfo &MRI,
18931893
case TargetOpcode::G_UADDSAT:
18941894
case TargetOpcode::G_SSUBSAT:
18951895
case TargetOpcode::G_USUBSAT:
1896+
case TargetOpcode::G_SBFX:
1897+
case TargetOpcode::G_UBFX:
18961898
return false;
18971899
case TargetOpcode::G_SSHLSAT:
18981900
case TargetOpcode::G_USHLSAT:

llvm/test/CodeGen/AArch64/GlobalISel/combine-freeze.mir

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1440,3 +1440,50 @@ body: |
14401440
%freeze:_(<4 x s32>) = G_FREEZE %extract
14411441
$q0 = COPY %freeze(<4 x s32>)
14421442
RET_ReallyLR implicit $x0
1443+
...
1444+
---
1445+
name: ubfx_does_not_generate_poison
1446+
body: |
1447+
bb.1:
1448+
liveins: $w0
1449+
1450+
; CHECK-LABEL: name: ubfx_does_not_generate_poison
1451+
; CHECK: liveins: $w0
1452+
; CHECK-NEXT: {{ $}}
1453+
; CHECK-NEXT: [[COPY:%[0-9]+]]:_(s64) = COPY $x0
1454+
; CHECK-NEXT: %c1:_(s64) = G_CONSTANT i64 1
1455+
; CHECK-NEXT: [[FREEZE:%[0-9]+]]:_(s64) = G_FREEZE [[COPY]]
1456+
; CHECK-NEXT: [[UBFX:%[0-9]+]]:_(s64) = G_UBFX [[FREEZE]], %c1(s64), %c1
1457+
; CHECK-NEXT: $x0 = COPY [[UBFX]](s64)
1458+
; CHECK-NEXT: RET_ReallyLR implicit $x0
1459+
%0:_(s64) = COPY $x0
1460+
%c1:_(s64) = G_CONSTANT i64 1
1461+
%1:_(s64) = G_UBFX %0, %c1, %c1
1462+
%2:_(s64) = G_FREEZE %1
1463+
$x0 = COPY %2(s64)
1464+
RET_ReallyLR implicit $x0
1465+
1466+
...
1467+
---
1468+
name: sbfx_does_not_generate_poison
1469+
body: |
1470+
bb.1:
1471+
liveins: $w0
1472+
1473+
; CHECK-LABEL: name: sbfx_does_not_generate_poison
1474+
; CHECK: liveins: $w0
1475+
; CHECK-NEXT: {{ $}}
1476+
; CHECK-NEXT: [[COPY:%[0-9]+]]:_(s64) = COPY $x0
1477+
; CHECK-NEXT: %c1:_(s64) = G_CONSTANT i64 1
1478+
; CHECK-NEXT: [[FREEZE:%[0-9]+]]:_(s64) = G_FREEZE [[COPY]]
1479+
; CHECK-NEXT: [[SBFX:%[0-9]+]]:_(s64) = G_SBFX [[FREEZE]], %c1(s64), %c1
1480+
; CHECK-NEXT: $x0 = COPY [[SBFX]](s64)
1481+
; CHECK-NEXT: RET_ReallyLR implicit $x0
1482+
%0:_(s64) = COPY $x0
1483+
%c1:_(s64) = G_CONSTANT i64 1
1484+
%1:_(s64) = G_SBFX %0, %c1, %c1
1485+
%2:_(s64) = G_FREEZE %1
1486+
$x0 = COPY %2(s64)
1487+
RET_ReallyLR implicit $x0
1488+
1489+
...

0 commit comments

Comments
 (0)