!FalseVal->getType()->isIntegerTy(1))
return getUnknown(V);
- // i1 cond ? i1 x : i1 C --> C + (umin_seq cond, x + C)
- if (isa<ConstantInt>(FalseVal)) {
- const SCEV *C = getSCEV(FalseVal);
- return getAddExpr(C, getUMinExpr(getSCEV(Cond),
- getAddExpr(C, getSCEV(TrueVal)),
- /*Sequential=*/true));
- }
-
- // i1 cond ? i1 C : i1 y --> C + (umin_seq ~cond, y + C)
- if (isa<ConstantInt>(TrueVal)) {
- const SCEV *C = getSCEV(TrueVal);
- return getAddExpr(C, getUMinExpr(getNotSCEV(getSCEV(Cond)),
- getAddExpr(C, getSCEV(FalseVal)),
- /*Sequential=*/true));
+ // i1 cond ? i1 x : i1 C --> C + (umin_seq cond, x + C)
+ // i1 cond ? i1 C : i1 x --> C + (umin_seq ~cond, x + C)
+ if (isa<ConstantInt>(TrueVal) || isa<ConstantInt>(FalseVal)) {
+ const SCEV *CondExpr = getSCEV(Cond);
+ const SCEV *TrueExpr = getSCEV(TrueVal);
+ const SCEV *FalseExpr = getSCEV(FalseVal);
+ const SCEV *X, *C;
+ if (isa<ConstantInt>(TrueVal)) {
+ CondExpr = getNotSCEV(CondExpr);
+ X = FalseExpr;
+ C = TrueExpr;
+ } else {
+ X = TrueExpr;
+ C = FalseExpr;
+ }
+ return getAddExpr(
+ C, getUMinExpr(CondExpr, getAddExpr(C, X), /*Sequential=*/true));
}
return getUnknown(V);