https://gcc.gnu.org/bugzilla/show_bug.cgi?id=124018
Bug ID: 124018
Summary: Improvce if-conversion of boolean values
Product: gcc
Version: 16.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: law at gcc dot gnu.org
Target Milestone: ---
Consider this code (from 523.xalancbmk) on rv64gcbv_zicond:
#include <stdbool.h>
bool isValidAncestorType(int type) {
if (type == 0 || type == 6 || type == 4) {
return true;
}
return false;
}
Currently compiles to a sequence like this:
li a4,6 # 8 [c=4 l=4] *movdi_64bit/1
li a5,81 # 33 [c=4 l=4] *movdi_64bit/1
bext a5,a5,a0 # 36 [c=4 l=4] *bextdi
sgtu a0,a0,a4 # 38 [c=4 l=4] *sgtu_didi
czero.nez a0,a5,a0 # 39 [c=4 l=4] *czero.nez.didi
But we could do better if gimple passed along better code. The .optimized dump
looks like:
if (_1 > 6)
goto <bb 4>; [33.00%]
else
goto <bb 3>; [67.00%]
;; succ: 3
;; 4
;; basic block 3, loop depth 0
;; pred: 2
_3 = 81 >> _1;
_8 = (_Bool) _3;
;; succ: 4
;; basic block 4, loop depth 0
;; pred: 3
;; 2
# _4 = PHI <_8(3), 0(2)>
_8 is a boolean value, so 0/1. And the other value in the PHI is 0. So it
seems like we can compute _1 < 7 into a temporary and do a logical and of that
with 81 >> _1. So final codegen would be something like
li a5,81
srl a5,a5,a0 (or bext a5,a5,a0)
sltui a0,a0,7
and a0,a5,a0
Or something along those lines. It's painful to do in RTL as we just have too
many instructions we need to combine. Gimple seems like the only option here.