llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

[MIPS] Select/Add combiner error with gp_rel addresses

Open keithdunwoody opened this issue 4 months ago • 6 comments

The instruction combiner optimizes (select (add $gp %gp_rel(a)) (add $gp %gp_rel(b))) into (add $gp (select %gp_rel(a) %gp_rel(b))). This then fails instruction selection because there's no matching rule.

Error here seems to be with the combiner step: the combiner should not be performing this optimization if one of the operands to the binary op is a legal immediate for that operation since this will unnecessarily materialize the constant.

Steps to reproduce:

RUN: llc -mtriple=mips -mcpu=mips32 -relocation-model=static -mgpopt -mattr=+noabicalls < llvm/test/CodeGen/Mips/cmov.ll

keithdunwoody avatar Jul 25 '26 19:07 keithdunwoody

@llvm/issue-subscribers-backend-mips

Author: keithdunwoody

The instruction combiner optimizes (select (add $gp %gp_rel(a)) (add $gp %gp_rel(b))) into (add $gp (select %gp_rel(b) %gp_rel(c))). This then fails instruction selection because there's no matching rule.

Error here seems to be with the combiner step: the combiner should not be performing this optimization if one of the operands to the binary op is a legal immediate for that operation since this will unnecessarily materialize the constant.

Steps to reproduce:

RUN: llc -mtriple=mips -mcpu=mips32 -relocation-model=static -mgpopt -mattr=+noabicalls < llvm/test/CodeGen/Mips/cmov.ll

Hey could i take this up?

david04g avatar Jul 26 '26 01:07 david04g

I do have a potential patch, but need to clean it up a bit.

keithdunwoody avatar Jul 26 '26 01:07 keithdunwoody

@david04g : All yours if you still want to take this up. A different approach than what I'd taken was requested, and I don't have the time to completely pivot. See comments in the PR for more details.

keithdunwoody avatar Aug 07 '26 19:08 keithdunwoody

I'll get to work on it and see what i can do

david04g avatar Aug 07 '26 20:08 david04g

@keithdunwoody @dtcxzyw forgot to ping but PR should be in line with what was disscussed in the PR rejection.

david04g avatar Aug 11 '26 19:08 david04g